This is the mail archive of the
binutils-cvs@sourceware.org
mailing list for the binutils project.
[binutils-gdb] Fix a potentially undefined right shift by replacing it with two smaller right shifts.
- From: Nick Clifton <nickc at sourceware dot org>
- To: bfd-cvs at sourceware dot org
- Date: 5 Mar 2015 17:27:03 -0000
- Subject: [binutils-gdb] Fix a potentially undefined right shift by replacing it with two smaller right shifts.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=41cd1ad1b9760ba962fde607ac218b5af760dfbf
commit 41cd1ad1b9760ba962fde607ac218b5af760dfbf
Author: Nick Clifton <nickc@redhat.com>
Date: Thu Mar 5 17:26:10 2015 +0000
Fix a potentially undefined right shift by replacing it with two smaller right shifts.
PR binutils/17765
* elflink.c (put_value): Avoid using an undefined shift
operation.
Diff:
---
bfd/ChangeLog | 6 ++++++
bfd/elflink.c | 18 +++++++++++-------
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index f29dec5..6810f6b 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2015-03-05 Nick Clifton <nickc@redhat.com>
+
+ PR binutils/17765
+ * elflink.c (put_value): Avoid using an undefined shift
+ operation.
+
2015-03-05 H.J. Lu <hongjiu.lu@intel.com>
PR ld/pr15228
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 6ee6499..b285e76 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -7793,28 +7793,32 @@ put_value (bfd_vma size,
{
location += (size - chunksz);
- for (; size; size -= chunksz, location -= chunksz, x >>= (chunksz * 8))
+ for (; size; size -= chunksz, location -= chunksz)
{
switch (chunksz)
{
- default:
- case 0:
- abort ();
case 1:
bfd_put_8 (input_bfd, x, location);
+ x >>= 8;
break;
case 2:
bfd_put_16 (input_bfd, x, location);
+ x >>= 16;
break;
case 4:
bfd_put_32 (input_bfd, x, location);
+ x >>= 32;
break;
- case 8:
#ifdef BFD64
+ case 8:
bfd_put_64 (input_bfd, x, location);
-#else
- abort ();
+ /* Computed this way because x >>= 64 is undefined if x is a 64-bit value. */
+ x >>= 32;
+ x >>= 32;
+ break;
#endif
+ default:
+ abort ();
break;
}
}