mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-17 07:53:51 +08:00
[gdb/exp] Fix UB in scalar_binop
When building gdb with -fsanitize=undefined, I run into: ... $ gdb -q -batch -ex "p -(-0x7fffffffffffffff - 1)" src/gdb/valarith.c:1385:10: runtime error: signed integer overflow: \ 0 - -9223372036854775808 cannot be represented in type 'long int' $1 = -9223372036854775808 ... Fix this by performing the substraction in scalar_binop using unsigned types. Tested on x86_64-linux.
This commit is contained in:
@ -1382,7 +1382,10 @@ scalar_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
|
||||
break;
|
||||
|
||||
case BINOP_SUB:
|
||||
v = v1 - v2;
|
||||
/* Avoid runtime error: signed integer overflow: \
|
||||
0 - -9223372036854775808 cannot be represented in type
|
||||
'long int'. */
|
||||
v = (ULONGEST)v1 - (ULONGEST)v2;
|
||||
break;
|
||||
|
||||
case BINOP_MUL:
|
||||
|
Reference in New Issue
Block a user