Guard against overflow.

The return value of Compare only need be positive/negative/0 -- the
magnitude doesn't matter.


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

Branch: refs/heads/master
Commit: fe29dae681d18c3472f33e04c23fdc970341c52f
Parents: 1be7e72
Author: Marvin Humphrey <mar...@rectangular.com>
Authored: Thu May 26 19:22:18 2016 -0700
Committer: Marvin Humphrey <mar...@rectangular.com>
Committed: Thu May 26 19:35:43 2016 -0700

----------------------------------------------------------------------
 core/Lucy/Index/PostingPool.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/fe29dae6/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index fefed8b..c29b1c9 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -155,7 +155,12 @@ PostPool_Compare_IMP(PostingPool *self, Obj **ptr_a, Obj 
**ptr_b) {
 
     if (comparison == 0) {
         // If a is a substring of b, it's less than b, so return a neg num.
-        comparison = a_len - b_len;
+        if (a_len < b_len) {
+            comparison = -1;
+        }
+        else if (a_len > b_len) {
+            comparison = 1;
+        }
 
         // Break ties by doc id.
         if (comparison == 0) {

Reply via email to