Skip to content

Commit f3edde2

Browse files
author
jan.nijtmans
committed
Fix [d1434179b5]: avoid signed integer overflow in AppendUtfToUtfRep()
1 parent 22325d1 commit f3edde2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

generic/tclStringObj.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,10 +1722,10 @@ AppendUtfToUtfRep(
17221722
objPtr->length = 0;
17231723
}
17241724
oldLength = objPtr->length;
1725-
newLength = numBytes + oldLength;
1726-
if (newLength < 0) {
1725+
if (numBytes > INT_MAX - oldLength) {
17271726
Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);
17281727
}
1728+
newLength = numBytes + oldLength;
17291729

17301730
stringPtr = GET_STRING(objPtr);
17311731
if (newLength > stringPtr->allocated) {

0 commit comments

Comments
 (0)