From a3f9774682fe110eef1d3005173b957ff4d784db Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 10 Aug 2021 12:54:51 -0700 Subject: [PATCH] Fix undefined variable reference in development version --- lib/Perl/Tidy/Formatter.pm | 16 +++++++++++++++- local-docs/BugLog.pod | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 71e36532..0a23345f 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -4732,7 +4732,21 @@ EOM if ( $rblock_type->[$j] ); } elsif ( $is_closing_token{$token} ) { - $nesting_depth--; + + # The opening depth should always be defined, and + # it should equal $nesting_depth-1. To protect + # against unforseen error conditions, however, we + # will check this and fix things if necessary. For + # a test case see issue c055. + my $opening_depth = + $rdepth_of_opening_seqno->[$seqno]; + if ( !defined($opening_depth) ) { + $opening_depth = $nesting_depth--; + $opening_depth = 0 if ( $opening_depth < 0 ); + $rdepth_of_opening_seqno->[$seqno] = + $opening_depth; + } + $nesting_depth = $opening_depth; $sign = -1; } elsif ( $token eq '?' ) { diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 989c0585..7c162ebf 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,20 @@ =over 4 +=item B + +In testing, the following unbalanced snippet caused a reference to an undefined +value in the current development version (but not in the current released +version). + + if($CPAN::Config->{term_is_latin}){ + $swhat=~s{([\xC0-\xDF])([\x80-\xBF])}{chr(ord($1)<<6&0xC0|ord($2)&0x3F)}eg;}if($self->colorize_output){if($CPAN::DEBUG&&$swhat=~/^Debug\(/){ + $ornament=$CPAN::Config->{colorize_debug}||"black on_cyan";} + +A check has been added to fix this. + +10 Aug 2021. + =item B Testing with random parameters produced unstable formatting with the -- 2.39.5