From: Karl Williamson Date: Mon, 20 Aug 2012 19:28:31 +0000 (-0600) Subject: mktables: Fix bug when deleting final range X-Git-Tag: upstream/5.20.0~5650 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5b348b71b6aa004c25b0c805567d95fd5476776e;p=platform%2Fupstream%2Fperl.git mktables: Fix bug when deleting final range 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. --- diff --git a/lib/unicore/mktables b/lib/unicore/mktables index 0be8b5b..7c5abc0 100644 --- a/lib/unicore/mktables +++ b/lib/unicore/mktables @@ -3015,6 +3015,10 @@ sub trace { return main::trace(@_); } 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; @@ -3070,9 +3074,7 @@ sub trace { return main::trace(@_); } 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} = []; @@ -4157,7 +4159,12 @@ sub trace { return main::trace(@_); } # 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; }