]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elfcmp: Make sure Elf32_Word difference doesn't wrap around in int compare.
authorMark Wielaard <mjw@redhat.com>
Tue, 16 Dec 2014 10:04:55 +0000 (11:04 +0100)
committerMark Wielaard <mjw@redhat.com>
Wed, 17 Dec 2014 15:30:33 +0000 (16:30 +0100)
Signed-off-by: Mark Wielaard <mjw@redhat.com>
src/ChangeLog
src/elfcmp.c

index 141b31f054d678acd044e6cc00414a98cea9ba77..1e612bf64fcc1c3bb2ea53bb36e1a629f6925ebf 100644 (file)
@@ -1,3 +1,8 @@
+2014-12-16  Mark Wielaard  <mjw@redhat.com>
+
+       * elfcmp.c (compare_Elf32_Word): Make sure (unsigned) Elf32_Word
+       difference doesn't wrap around before returning as int.
+
 2014-12-11  Mark Wielaard  <mjw@redhat.com>
 
        * readelf.c (print_debug_exception_table): Check TType base offset
index c420019f58e5d4791612527e40ac30ba7687982f..d1008b3c3e2f5bb3ecc80651ffe05995bd45fb96 100644 (file)
@@ -811,8 +811,7 @@ compare_Elf32_Word (const void *p1, const void *p2)
 {
   const Elf32_Word *w1 = p1;
   const Elf32_Word *w2 = p2;
-  assert (sizeof (int) >= sizeof (*w1));
-  return (int) *w1 - (int) *w2;
+  return *w1 < *w2 ? -1 : *w1 > *w2 ? 1 : 0;
 }
 
 static int