Fix signed left shift in vm_loop().

Signed left shift operations are undefined in C. Add constants for the minimum/maximum integer value which are already shifted. Technically, the constant for the shifted maximum value is not required, adding it for consistency/increased readability.

The bug was detected by -Wshift-negative-value both with GCC 6.x and Clang.

This fixes #1174.

JerryScript-DCO-1.0-Signed-off-by: Tilmann Scheller t.scheller@samsung.com
This commit is contained in:
Tilmann Scheller
2016-07-05 21:11:54 +02:00
parent 5f7997d2d0
commit fb9b4dd807
2 changed files with 14 additions and 6 deletions
+2 -2
View File
@@ -1215,12 +1215,12 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
if (opcode_flags & VM_OC_DECREMENT_OPERATOR_FLAG)
{
if (int_value > (ECMA_INTEGER_NUMBER_MIN << ECMA_DIRECT_SHIFT))
if (int_value > ECMA_INTEGER_NUMBER_MIN_SHIFTED)
{
int_increase = -(1 << ECMA_DIRECT_SHIFT);
}
}
else if (int_value < (ECMA_INTEGER_NUMBER_MAX << ECMA_DIRECT_SHIFT))
else if (int_value < ECMA_INTEGER_NUMBER_MAX_SHIFTED)
{
int_increase = 1 << ECMA_DIRECT_SHIFT;
}