Adapt PolyReader_sub_tick for changes to I32Array.

Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/bb4f6e44
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/bb4f6e44
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/bb4f6e44

Branch: refs/heads/master
Commit: bb4f6e44bc55664f7ac4ec5e3c318619ffa6f8f2
Parents: 0c49408
Author: Marvin Humphrey <mar...@rectangular.com>
Authored: Tue Apr 5 19:02:38 2016 -0700
Committer: Marvin Humphrey <mar...@rectangular.com>
Committed: Wed Apr 6 13:03:09 2016 -0700

----------------------------------------------------------------------
 core/Lucy/Index/PolyReader.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/bb4f6e44/core/Lucy/Index/PolyReader.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PolyReader.c b/core/Lucy/Index/PolyReader.c
index 5c807d2..37dfcec 100644
--- a/core/Lucy/Index/PolyReader.c
+++ b/core/Lucy/Index/PolyReader.c
@@ -550,16 +550,19 @@ PolyReader_Get_Seg_Readers_IMP(PolyReader *self) {
 
 uint32_t
 PolyReader_sub_tick(I32Array *offsets, int32_t doc_id) {
-    int32_t size = I32Arr_Get_Size(offsets);
+    size_t size = I32Arr_Get_Size(offsets);
     if (size == 0) {
         return 0;
     }
+    else if (size > INT32_MAX) {
+        THROW(ERR, "Unexpectedly large offsets array: %u64", (uint64_t)size);
+    }
 
     int32_t lo = -1;
-    int32_t hi = size;
+    int32_t hi = (int32_t)size;
     while (hi - lo > 1) {
         int32_t mid = lo + ((hi - lo) / 2);
-        int32_t offset = I32Arr_Get(offsets, mid);
+        int32_t offset = I32Arr_Get(offsets, (size_t)mid);
         if (doc_id <= offset) {
             hi = mid;
         }
@@ -567,12 +570,12 @@ PolyReader_sub_tick(I32Array *offsets, int32_t doc_id) {
             lo = mid;
         }
     }
-    if (hi == size) {
+    if (hi == (int32_t)size) {
         hi--;
     }
 
     while (hi > 0) {
-        int32_t offset = I32Arr_Get(offsets, hi);
+        int32_t offset = I32Arr_Get(offsets, (size_t)hi);
         if (doc_id <= offset) {
             hi--;
         }

Reply via email to