summaryrefslogtreecommitdiff
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 11:16:11 +0900
commit85f0048d22a31f34d991e56757560f1b39c007b6 (patch)
treea732e253349a798aab8cfd2241dc27532abd95e0
parent46b6870ffac26fc360a00120a402535ed4ee836d (diff)
mp_bytecode_print_str: avoid undefined behavior
Left shift of negative numbers is undefined in the "C" standard. Multiplying by 128 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.
-rw-r--r--py/showbc.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/py/showbc.c b/py/showbc.c
index 3deb18cd3..e71d8a253 100644
--- a/py/showbc.c
+++ b/py/showbc.c
@@ -185,7 +185,7 @@ const byte *mp_bytecode_print_str(const byte *ip) {
num--;
}
do {
- num = (num << 7) | (*ip & 0x7f);
+ num = (num * 128) | (*ip & 0x7f);
} while ((*ip++ & 0x80) != 0);
printf("LOAD_CONST_SMALL_INT " INT_FMT, num);
break;