mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-27 01:28:46 +00:00
_mul_overflow and get_encoded_value
A sufficiently mad compiler optimiser can take undefined behaviour according to the C standard as an opportunity to remove code. Since "data + size" might be seen to be past the end of an array, calculating such an expression is UB. _mul_overflow is infrastructure for later patches. * bucomm.h (_mul_overflow): Define. * dwarf.c (get_encoded_value): Avoid pointer UB.
This commit is contained in:
@@ -80,4 +80,12 @@ void *xmalloc (size_t);
|
||||
|
||||
void *xrealloc (void *, size_t);
|
||||
|
||||
#if __GNUC__ >= 7
|
||||
#define _mul_overflow(a, b, res) __builtin_mul_overflow (a, b, res)
|
||||
#else
|
||||
/* Assumes unsigned values. Careful! Args evaluated multiple times. */
|
||||
#define _mul_overflow(a, b, res) \
|
||||
((*res) = (a), (*res) *= (b), (b) != 0 && (*res) / (b) != (a))
|
||||
#endif
|
||||
|
||||
#endif /* _BUCOMM_H */
|
||||
|
||||
Reference in New Issue
Block a user