diff options
author | sebres <sebres@users.sourceforge.net> | 2017-06-06 08:34:00 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2017-06-06 08:34:00 (GMT) |
commit | 1172340e247bd64f10a4c5e5b812bd5283ffbb83 (patch) | |
tree | 5d0fab5d7288ebc9c820bcd377b3f4614a46f7b1 /generic | |
parent | 735ced34c942925be92107aa7752ab143eaf6fb2 (diff) | |
download | tcl-1172340e247bd64f10a4c5e5b812bd5283ffbb83.zip tcl-1172340e247bd64f10a4c5e5b812bd5283ffbb83.tar.gz tcl-1172340e247bd64f10a4c5e5b812bd5283ffbb83.tar.bz2 |
small code review: don't need to check length if unchanged + the same case if 0 length
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclStringObj.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index a4c242a..c1c15f2 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -2897,7 +2897,7 @@ TclStringCatObjv( if (binary) { /* Result will be pure byte array. Pre-size it */ ov = objv; oc = objc; - while (oc-- && (length >= 0)) { + while (oc--) { objPtr = *ov++; if (objPtr->bytes == NULL) { @@ -2909,14 +2909,16 @@ TclStringCatObjv( if (length == 0) { first = last; } + if ((length += numBytes) < 0) { + break; /* overflow */ + } } - length += numBytes; } } } else if (allowUniChar && requestUniChar) { /* Result will be pure Tcl_UniChar array. Pre-size it. */ ov = objv; oc = objc; - while (oc-- && (length >= 0)) { + while (oc--) { objPtr = *ov++; if ((objPtr->bytes == NULL) || (objPtr->length)) { @@ -2929,13 +2931,15 @@ TclStringCatObjv( first = last; } } - length += numChars; + if ((length += numChars) < 0) { + break; /* overflow */ + } } } } else { /* Result will be concat of string reps. Pre-size it. */ ov = objv; oc = objc; - while (oc-- && (length >= 0)) { + while (oc--) { int numBytes; objPtr = *ov++; @@ -2946,11 +2950,19 @@ TclStringCatObjv( if (length == 0) { first = last; } + if ((length += numBytes) < 0) { + break; /* overflow */ + } } - length += numBytes; } } + if (last == first || length == 0) { + /* Only one non-empty value or zero length; return first */ + *objPtrPtr = objv[first]; + return TCL_OK; + } + if (length < 0) { if (interp) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( @@ -2960,17 +2972,6 @@ TclStringCatObjv( return TCL_ERROR; } - if (length == 0) { - /* Total length of zero means every value has length zero */ - *objPtrPtr = objv[0]; - return TCL_OK; - } - if (last == first) { - /* Only one non-empty value; return it */ - *objPtrPtr = objv[first]; - return TCL_OK; - } - objv += first; objc = (last - first + 1); if (binary) { |