When a Range_List is emptied, there is a bug which causes a runtime
error when trying to refer to a non-existent element. This avoids that.
A future commit would have run afoul of this bug.
our $addr;
+ # Max is initialized to a negative value that isn't adjacent to 0, for
+ # simpler tests
+ my $max_init = -2;
+
main::setup_package();
my %ranges;
Carp::carp_extra_args(\%args) if main::DEBUG && %args;
- # Max is initialized to a negative value that isn't adjacent to 0,
- # for simpler tests
- $max{$addr} = -2;
+ $max{$addr} = $max_init;
$_search_ranges_cache{$addr} = 0;
$ranges{$addr} = [];
# otherwise recalculate it. This is done too rarely to worry about
# performance.
if ($operation eq '-' && @return) {
- $max{$addr} = $r->[-1]->end;
+ if (@$r) {
+ $max{$addr} = $r->[-1]->end;
+ }
+ else { # Now empty
+ $max{$addr} = $max_init;
+ }
}
return @return;
}