From 85f0048d22a31f34d991e56757560f1b39c007b6 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 8 Oct 2019 10:48:25 +0900 Subject: 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. --- py/showbc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'py/showbc.c') 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; -- cgit v1.2.3