diff options
author | dgp <dgp@users.sourceforge.net> | 2016-11-30 03:16:46 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2016-11-30 03:16:46 (GMT) |
commit | 369dcc22d77b8350b299e2d744e7a51f78571296 (patch) | |
tree | 10240f2048ddeb7265ab7c24bcb5b6cb4e70db48 /generic/tclCmdMZ.c | |
parent | ad494f5289c3b0ab3acc82cae88d4a9729f5390d (diff) | |
parent | 0004d6152456219c0ef09046c169ad3ad7532ee1 (diff) | |
download | tcl-369dcc22d77b8350b299e2d744e7a51f78571296.zip tcl-369dcc22d77b8350b299e2d744e7a51f78571296.tar.gz tcl-369dcc22d77b8350b299e2d744e7a51f78571296.tar.bz2 |
merge trunk
Diffstat (limited to 'generic/tclCmdMZ.c')
-rw-r--r-- | generic/tclCmdMZ.c | 54 |
1 files changed, 4 insertions, 50 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 9048c39..41b7aa8 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -2119,9 +2119,7 @@ StringReptCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - const char *string1; - char *string2; - int count, index, length1, length2; + int count; Tcl_Obj *resultPtr; if (objc != 3) { @@ -2139,59 +2137,15 @@ StringReptCmd( if (count == 1) { Tcl_SetObjResult(interp, objv[1]); - goto done; + return TCL_OK; } else if (count < 1) { - goto done; - } - string1 = TclGetStringFromObj(objv[1], &length1); - if (length1 <= 0) { - goto done; - } - - /* - * Only build up a string that has data. Instead of building it up with - * repeated appends, we just allocate the necessary space once and copy - * the string value in. - * - * We have to worry about overflow [Bugs 714106, 2561746]. - * At this point we know 1 <= length1 <= INT_MAX and 2 <= count <= INT_MAX. - * We need to keep 2 <= length2 <= INT_MAX. - */ - - if (count > INT_MAX/length1) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "result exceeds max size for a Tcl value (%d bytes)", - INT_MAX)); - Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL); - return TCL_ERROR; + return TCL_OK; } - length2 = length1 * count; - TclNewObj(resultPtr); - Tcl_InvalidateStringRep(resultPtr); - string2 = Tcl_InitStringRep(resultPtr, NULL, length2); - if (string2 == NULL) { - /* - * Alloc failed. Note that in this case we try to do an error message - * since this is a case that's most likely when the alloc is large and - * that's easy to do with this API. Note that if we fail allocating a - * short string, this will likely keel over too (and fatally). - */ - - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "string size overflow, out of memory allocating %u bytes", - length2 + 1)); - Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL); - Tcl_DecrRefCount(resultPtr); + if (TCL_OK != TclStringRepeat(interp, objv[1], count, &resultPtr)) { return TCL_ERROR; } - for (index = 0; index < count; index++) { - memcpy(string2 + (length1 * index), string1, (size_t) length1); - } - (void) Tcl_InitStringRep(resultPtr, NULL, length2); Tcl_SetObjResult(interp, resultPtr); - - done: return TCL_OK; } |