summaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2014-10-14 13:36:20 +1030
committerAlan Modra <amodra@gmail.com>2014-10-14 14:36:35 +1030
commit65879393f04e14a9ab8797a8e66e0ec8d94108b5 (patch)
tree7f4300ec569ff44c6fd1c412f4ddad82d040477c /bfd
parent9495b2e66f772783eb89cfa755e1e09641fa44eb (diff)
downloadbinutils-gdb-65879393f04e14a9ab8797a8e66e0ec8d94108b5.tar.gz
Avoid undefined behaviour with signed expressions
PR 17453 bfd/ * libbfd.c (COERCE16, COERCE32, COERCE64): Use unsigned types. (EIGHT_GAZILLION): Delete. binutils/ * dwarf.c (read_leb128): Avoid signed overflow. (read_debug_line_header): Likewise. gas/ * config/tc-i386.c (fits_in_signed_long): Use unsigned param and expression to avoid signed overflow. (fits_in_signed_byte, fits_in_unsigned_byte, fits_in_unsigned_word, fits_in_signed_word, fits_in_unsigned_long): Similarly. * expr.c (operand <'-'>): Avoid signed overflow. * read.c (s_comm_internal): Likewise.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog6
-rw-r--r--bfd/libbfd.c7
2 files changed, 9 insertions, 4 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index be3ae3857b2..f9e81d3ef55 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2014-10-14 Alan Modra <amodra@gmail.com>
+
+ PR 17453
+ * libbfd.c (COERCE16, COERCE32, COERCE64): Use unsigned types.
+ (EIGHT_GAZILLION): Delete.
+
2014-10-13 Alan Modra <amodra@gmail.com>
PR 17467
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index 6676dffb045..d98a9d28a69 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -548,11 +548,10 @@ DESCRIPTION
.*/
/* Sign extension to bfd_signed_vma. */
-#define COERCE16(x) (((bfd_signed_vma) (x) ^ 0x8000) - 0x8000)
-#define COERCE32(x) (((bfd_signed_vma) (x) ^ 0x80000000) - 0x80000000)
-#define EIGHT_GAZILLION ((bfd_int64_t) 1 << 63)
+#define COERCE16(x) (((bfd_vma) (x) ^ 0x8000) - 0x8000)
+#define COERCE32(x) (((bfd_vma) (x) ^ 0x80000000) - 0x80000000)
#define COERCE64(x) \
- (((bfd_int64_t) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION)
+ (((bfd_uint64_t) (x) ^ ((bfd_uint64_t) 1 << 63)) - ((bfd_uint64_t) 1 << 63))
bfd_vma
bfd_getb16 (const void *p)