summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2019-10-08 10:48:25 +0900
committerJeff Epler <jepler@gmail.com>2019-10-08 10:48:25 +0900
commit0d96f1906b66139beebc13c55078aaf610c76968 (patch)
treeabd0b6ea03c1dfd7daf6a1b5e97a3fe047963ade /py
parent4eb11fbde65872bf3385bfd1b487adf72eec4016 (diff)
mp_binary_get_int: avoid undefined behavior
Left shift of negative numbers is undefined in the "C" standard. Multiplying by 256 has the intended effect (in the absence of integer overflow, anyway), can be implemented using the same shift instruction, but does not invoke undefined behavior. This problem was found using clang 7's scan-build static analyzer.
Diffstat (limited to 'py')
-rw-r--r--py/binary.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/py/binary.c b/py/binary.c
index 6b46425cf..2ec12fa93 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -184,7 +184,7 @@ long long mp_binary_get_int(mp_uint_t size, bool is_signed, bool big_endian, con
val = -1;
}
for (uint i = 0; i < size; i++) {
- val <<= 8;
+ val *= 256;
val |= *src;
src += delta;
}