From fc4f706d6d37bab8cda71cc69183591cb1a9a2e4 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Tue, 21 Aug 2012 11:24:48 -0600 Subject: [PATCH] regcomp.c: Add assertion, comments --- regcomp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/regcomp.c b/regcomp.c index 263b7b4..5fb6532 100644 --- a/regcomp.c +++ b/regcomp.c @@ -7343,10 +7343,12 @@ Perl__invlist_search(pTHX_ SV* const invlist, const UV cp) /* Binary search. What we are looking for is such that * array[i] <= cp < array[i+1] - * The loop below converges on the i+1. */ + * The loop below converges on the i+1. Note that there may not be an + * (i+1)th element in the array, and things work nonetheless */ while (low < high) { IV mid = (low + high) / 2; - if (array[mid] <= cp) { + assert(mid <= highest_element); + if (array[mid] <= cp) { /* cp >= array[mid] */ low = mid + 1; /* We could do this extra test to exit the loop early. -- 1.8.3.1