[pfr] Fix binary search (#47514). * src/pfr/pfrsbit.c (pfr_lookup_bitmap_data): Handle border conditions correctly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
diff --git a/ChangeLog b/ChangeLog
index e7e92c1..2473546 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2016-03-29 Werner Lemberg <wl@gnu.org>
+ [pfr] Fix binary search (#47514).
+
+ * src/pfr/pfrsbit.c (pfr_lookup_bitmap_data): Handle border
+ conditions correctly.
+
+2016-03-29 Werner Lemberg <wl@gnu.org>
+
[pfr] Minor.
* src/pfr/pfrsbit.c (pfr_lookup_bitmap_data): Replace `left',
diff --git a/src/pfr/pfrsbit.c b/src/pfr/pfrsbit.c
index abdbb20..68da033 100644
--- a/src/pfr/pfrsbit.c
+++ b/src/pfr/pfrsbit.c
@@ -364,13 +364,12 @@
else
code = PFR_NEXT_BYTE( buff );
- if ( code == char_code )
- goto Found_It;
-
- if ( code < char_code )
- min = mid;
- else
+ if ( char_code < code )
max = mid;
+ else if ( char_code > code )
+ min = mid + 1;
+ else
+ goto Found_It;
}
Fail:
diff --git a/src/sfnt/ttcmap.c b/src/sfnt/ttcmap.c
index 8f9e3c1..01255a8 100644
--- a/src/sfnt/ttcmap.c
+++ b/src/sfnt/ttcmap.c
@@ -3104,7 +3104,7 @@
if ( char_code < start )
max = mid;
- else if ( char_code > start+cnt )
+ else if ( char_code > start + cnt )
min = mid + 1;
else
return TRUE;