diff options
author | nijtmans <nijtmans> | 2011-01-17 12:34:43 (GMT) |
---|---|---|
committer | nijtmans <nijtmans> | 2011-01-17 12:34:43 (GMT) |
commit | c19c3f2d6de6320a78e1a5fc90c832a6247f8f9c (patch) | |
tree | eb3bdd86b4865143cbbb942e9c4126b8dfb2ba89 /generic/tclIOCmd.c | |
parent | 0389645b34a0b9251ca8ea19bce38a41501cc991 (diff) | |
download | tcl-c19c3f2d6de6320a78e1a5fc90c832a6247f8f9c.zip tcl-c19c3f2d6de6320a78e1a5fc90c832a6247f8f9c.tar.gz tcl-c19c3f2d6de6320a78e1a5fc90c832a6247f8f9c.tar.bz2 |
[Bug 3148192]: Commands "read/puts" incorrectly interpret parameters.
Improved error-message regarding legacy form.
Diffstat (limited to 'generic/tclIOCmd.c')
-rw-r--r-- | generic/tclIOCmd.c | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c index dce8ed7..3827b8e 100644 --- a/generic/tclIOCmd.c +++ b/generic/tclIOCmd.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIOCmd.c,v 1.51.2.3 2010/02/11 15:25:25 dkf Exp $ + * RCS: @(#) $Id: tclIOCmd.c,v 1.51.2.4 2011/01/17 12:34:44 nijtmans Exp $ */ #include "tclInt.h" @@ -135,32 +135,24 @@ Tcl_PutsObjCmd( break; case 4: /* [puts -nonewline $chan $x] or [puts $chan $x nonewline] */ + newline = 0; if (strcmp(TclGetString(objv[1]), "-nonewline") == 0) { chanObjPtr = objv[2]; string = objv[3]; - } else { + break; + } else if (strcmp(TclGetString(objv[2]), "nonewline") == 0) { /* * The code below provides backwards compatibility with an old * form of the command that is no longer recommended or - * documented. + * documented. See also [Bug #3151675]. Will be removed in Tcl 9, + * maybe even earlier. */ - char *arg; - int length; - - arg = TclGetStringFromObj(objv[3], &length); - if ((length != 9) - || (strncmp(arg, "nonewline", (size_t) length) != 0)) { - Tcl_AppendResult(interp, "bad argument \"", arg, - "\": should be \"nonewline\"", NULL); - return TCL_ERROR; - } chanObjPtr = objv[1]; string = objv[2]; + break; } - newline = 0; - break; - + /* Fall through */ default: /* [puts] or [puts some bad number of arguments...] */ Tcl_WrongNumArgs(interp, 1, objv, "?-nonewline? ?channelId? string"); @@ -429,24 +421,28 @@ Tcl_ReadObjCmd( i++; /* Consumed channel name. */ /* - * Compute how many bytes to read, and see whether the final newline - * should be dropped. + * Compute how many bytes to read. */ toRead = -1; if (i < objc) { - char *arg; + if (TclGetIntFromObj(interp, objv[i], &toRead) != TCL_OK) { + /* + * The code below provides backwards compatibility with an old + * form of the command that is no longer recommended or + * documented. See also [Bug #3151675]. Will be removed in Tcl 9, + * maybe even earlier. + */ - arg = TclGetString(objv[i]); - if (isdigit(UCHAR(arg[0]))) { /* INTL: digit */ - if (TclGetIntFromObj(interp, objv[i], &toRead) != TCL_OK) { - return TCL_ERROR; + if (strcmp(TclGetString(objv[i]), "nonewline") != 0) { + return TCL_ERROR; } - } else if (strcmp(arg, "nonewline") == 0) { newline = 1; - } else { - Tcl_AppendResult(interp, "bad argument \"", arg, - "\": should be \"nonewline\"", NULL); + } else if (toRead < 0) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "expected non-negative integer but got \"", + TclGetString(objv[i]), "\"", NULL); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "NUMBER", NULL); return TCL_ERROR; } } |