Subject: | the loop attempts to read after $max |
Date: | Tue, 8 Jun 2010 15:11:12 +0200 |
To: | bug-Search-Binary [...] rt.cpan.org |
From: | Krzysztof Żelechowski <giecrilj [...] stegny.2a.pl> |
Code:
sub arr_read_rec (\@$;$)
{
my ($handle, $val, $pos) = @_;
$pos = $$handle [01] + 01 unless (defined ($pos));
print $val,$pos,@$handle;
$$handle [01] = $pos;
return $val <=> $pos, $pos; }
if (01) { $\ = '
'; $, = ',';
print 2 * binary_search 0, 0177, 0201, \&arr_read_rec, [0, 0], 01;
exit; }
Output:
129,63,0,0
129,95,0,63
129,111,0,95
129,119,0,111
129,123,0,119
129,125,0,123
129,126,0,125
129,126,0,126
129,127,0,126
129,128,0,127 # this should never happen!
256
As a workaround, the callback function must treat all off-range access as
greater.