diff options
| -rw-r--r-- | generic/tclBinary.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/generic/tclBinary.c b/generic/tclBinary.c index 2b15d31..e123513 100644 --- a/generic/tclBinary.c +++ b/generic/tclBinary.c @@ -2808,14 +2808,16 @@ BinaryEncodeUu( } *cursor++ = UueDigits[lineLen]; for (i = 0 ; i < lineLen ; i++) { - n <<= 8; + /* Left shift cast to unsigned type to prevent UB on overflow */ + n = (Tcl_Size)((size_t)n << 8); n |= data[offset++]; for (bits += 8; bits > 6 ; bits -= 6) { *cursor++ = UueDigits[(n >> (bits - 6)) & 0x3F]; } } if (bits > 0) { - n <<= 8; + /* Left shift cast to unsigned type to prevent UB on overflow */ + n = (Tcl_Size)((size_t)n << 8); *cursor++ = UueDigits[(n >> (bits + 2)) & 0x3F]; bits = 0; } |
