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.
This commit is contained in:
parent
46b6870ffa
commit
85f0048d22
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user