Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/lib/libunwind Fix binary search when search value is in ...



details:   https://anonhg.NetBSD.org/src/rev/4377635ebb49
branches:  trunk
changeset: 806047:4377635ebb49
user:      joerg <joerg%NetBSD.org@localhost>
date:      Thu Jan 29 20:05:56 2015 +0000

description:
Fix binary search when search value is in the last block, but not equal
to the start of the range. PR 49444.

diffstat:

 sys/lib/libunwind/AddressSpace.hpp |  14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diffs (31 lines):

diff -r 63ac1a2c8bcd -r 4377635ebb49 sys/lib/libunwind/AddressSpace.hpp
--- a/sys/lib/libunwind/AddressSpace.hpp        Thu Jan 29 19:57:08 2015 +0000
+++ b/sys/lib/libunwind/AddressSpace.hpp        Thu Jan 29 20:05:56 2015 +0000
@@ -263,21 +263,19 @@
 
     pint_t base = n->hdr_base;
     pint_t first = n->hdr_start;
-    pint_t len = n->hdr_entries;
-    while (len) {
-      pint_t next = first + ((len + 1) / 2) * 8;
+    for (pint_t len = n->hdr_entries; len > 1; ) {
+      pint_t next = first + (len / 2) * 8;
       pint_t nextPC = base + (int32_t)get32(next);
       if (nextPC == pc) {
         first = next;
         break;
       }
       if (nextPC < pc) {
-        len -= (len + 1) / 2;
         first = next;
-      } else if (len == 1)
-        break;
-      else
-        len = (len + 1) / 2;
+        len -= (len / 2);
+      } else {
+        len /= 2;
+      }
     }
     fdeStart = base + (int32_t)get32(first + 4);
     data_base = n->data_base;



Home | Main Index | Thread Index | Old Index