(long long)-UINT32_MAX leads to value 1 which is not what we expect.
This is due to implicit type promotion from unsigned to signed 32-bit
integer.
Apply this to 8-bit and 16-bit types as well even though they are
not affected by this issue to keep things regular.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
}
if (v > 0 && (v >= U8_MAX || n < old))
overflow = true;
- else if (v < 0 && (v <= -U8_MAX || n > old))
+ else if (v < 0 && (v <= -(s64) U8_MAX || n > old))
underflow = true;
break;
}
}
if (v > 0 && (v >= U16_MAX || n < old))
overflow = true;
- else if (v < 0 && (v <= -U16_MAX || n > old))
+ else if (v < 0 && (v <= -(s64) U16_MAX || n > old))
underflow = true;
break;
}
}
if (v > 0 && (v >= U32_MAX || n < old))
overflow = true;
- else if (v < 0 && (v <= -U32_MAX || n > old))
+ else if (v < 0 && (v <= -(s64) U32_MAX || n > old))
underflow = true;
break;
}