Skip to content

Commit 6cd069d

Browse files
committed
[CID 14868] libscript: Bad bit shift operation.
Temporary fix to make Coverity happy. This allows LCB bit shifting by any amount. A proper fix will ensure that left shifting is an error if it causes overflow.
1 parent 9827c6a commit 6cd069d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

libscript/src/module-bitwise.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ extern "C" MC_DLLEXPORT void MCBitwiseEvalBitwiseShift(integer_t p_operand, bool
4949
p_is_right = !p_is_right;
5050
}
5151

52+
/* Shifting integer_t by more than 31 bits is undefined */
53+
integer_t t_max_shift = (sizeof(integer_t) << 3) - 1;
54+
p_shift = MCMin (p_shift, t_max_shift);
55+
5256
if (p_is_right)
5357
r_output = p_operand >> p_shift;
5458
else

0 commit comments

Comments
 (0)