diff --git generic/tclDictObj.c generic/tclDictObj.c
index ba9ab98ed..9d7f5c64a 100644
--- generic/tclDictObj.c
+++ generic/tclDictObj.c
@@ -528,7 +528,7 @@ UpdateStringOfDict(
 	flagPtr[i] = ( i ? TCL_DONT_QUOTE_HASH : 0 );
 	keyPtr = Tcl_GetHashKey(&dict->table, &cPtr->entry);
 	elem = TclGetStringFromObj(keyPtr, &length);
-	bytesNeeded += TclScanElement(elem, length, flagPtr+i);
+	bytesNeeded += (unsigned int)TclScanElement(elem, length, flagPtr+i);
 	if (bytesNeeded < 0) {
 	    Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);
 	}
@@ -536,7 +536,7 @@ UpdateStringOfDict(
 	flagPtr[i+1] = TCL_DONT_QUOTE_HASH;
 	valuePtr = Tcl_GetHashValue(&cPtr->entry);
 	elem = TclGetStringFromObj(valuePtr, &length);
-	bytesNeeded += TclScanElement(elem, length, flagPtr+i+1);
+	bytesNeeded += (unsigned int)TclScanElement(elem, length, flagPtr+i+1);
 	if (bytesNeeded < 0) {
 	    Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);
 	}
