From: Steve Hancock Date: Tue, 26 May 2020 22:20:25 +0000 (-0700) Subject: fixed potential index problem; added test case for hanging side comments X-Git-Tag: 20200619~19 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=86081f7f3c183e294662ee7b745ea36b4ccda652;p=perltidy.git fixed potential index problem; added test case for hanging side comments --- diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index df7f7a6b..87d9e11a 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -2627,6 +2627,7 @@ sub delete_unmatched_tokens { my @min_levels; my $jmax = @{$rnew_lines} - 1; + return unless $jmax >= 0; my %is_good_tok; diff --git a/t/snippets/expect/hanging_side_comments3.def b/t/snippets/expect/hanging_side_comments3.def new file mode 100644 index 00000000..e0d9529e --- /dev/null +++ b/t/snippets/expect/hanging_side_comments3.def @@ -0,0 +1,12 @@ + if ( $var eq 'wastebasket' ) { # this sends a pure block + # of hanging side comments + #to the vertical aligner. + #It caused a crash in + #a test version of + #sub 'delete_unmatched_tokens' + #... + #} + } + elsif ( $var eq 'spacecommand' ) { + &die("No $val function") unless eval "defined &$val"; + } diff --git a/t/snippets/hanging_side_comments3.in b/t/snippets/hanging_side_comments3.in new file mode 100644 index 00000000..e0d9529e --- /dev/null +++ b/t/snippets/hanging_side_comments3.in @@ -0,0 +1,12 @@ + if ( $var eq 'wastebasket' ) { # this sends a pure block + # of hanging side comments + #to the vertical aligner. + #It caused a crash in + #a test version of + #sub 'delete_unmatched_tokens' + #... + #} + } + elsif ( $var eq 'spacecommand' ) { + &die("No $val function") unless eval "defined &$val"; + } diff --git a/t/snippets/kpit.in b/t/snippets/kpit.in index 001886f4..5c640af3 100644 --- a/t/snippets/kpit.in +++ b/t/snippets/kpit.in @@ -1 +1 @@ -if ( seek( DATA, 0, 0 ) ) { ... } +if ( seek(DATA, 0, 0) ) { ... } diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 05dddc9e..6b456710 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -245,6 +245,10 @@ ../snippets20.t git25.def ../snippets20.t git25.git25 ../snippets20.t outdent.outdent2 +../snippets20.t kpit.def +../snippets20.t kpit.kpit +../snippets20.t kpitl.def +../snippets20.t kpitl.kpitl ../snippets3.t ce_wn1.ce_wn ../snippets3.t ce_wn1.def ../snippets3.t colin.colin @@ -385,7 +389,4 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets20.t kpit.def -../snippets20.t kpit.kpit -../snippets20.t kpitl.def -../snippets20.t kpitl.kpitl +../snippets20.t hanging_side_comments3.def diff --git a/t/snippets/rperl.par b/t/snippets/rperl.par index 7e615cc5..fdd4c69e 100644 --- a/t/snippets/rperl.par +++ b/t/snippets/rperl.par @@ -1 +1 @@ --l=0 +-pbp -nst --ignore-side-comment-lengths --converge -l=0 -q diff --git a/t/snippets17.t b/t/snippets17.t index 7d973fd2..779b6fb1 100644 --- a/t/snippets17.t +++ b/t/snippets17.t @@ -65,8 +65,9 @@ BEGIN { 'def' => "", 'long_line' => "-l=0", 'pbp' => "-pbp -nst -nse", - 'rperl' => "-l=0", - 'rt132059' => "-dac", + 'rperl' => + "-pbp -nst --ignore-side-comment-lengths --converge -l=0 -q", + 'rt132059' => "-dac", }; ############################ diff --git a/t/snippets20.t b/t/snippets20.t index fbead065..fe88ed0a 100644 --- a/t/snippets20.t +++ b/t/snippets20.t @@ -18,6 +18,7 @@ #15 kpit.kpit #16 kpitl.def #17 kpitl.kpitl +#18 hanging_side_comments3.def # To locate test #13 you can search for its name or the string '#13' @@ -114,10 +115,25 @@ my $mapping = [ 'foo10' => undef, }; +---------- + + 'hanging_side_comments3' => <<'----------', + if ( $var eq 'wastebasket' ) { # this sends a pure block + # of hanging side comments + #to the vertical aligner. + #It caused a crash in + #a test version of + #sub 'delete_unmatched_tokens' + #... + #} + } + elsif ( $var eq 'spacecommand' ) { + &die("No $val function") unless eval "defined &$val"; + } ---------- 'kpit' => <<'----------', -if ( seek( DATA, 0, 0 ) ) { ... } +if ( seek(DATA, 0, 0) ) { ... } ---------- 'kpitl' => <<'----------', @@ -523,6 +539,25 @@ return ( $r**$n ) * (4**(int($n / 2) + 1))); #17........... }, + + 'hanging_side_comments3.def' => { + source => "hanging_side_comments3", + params => "def", + expect => <<'#18...........', + if ( $var eq 'wastebasket' ) { # this sends a pure block + # of hanging side comments + #to the vertical aligner. + #It caused a crash in + #a test version of + #sub 'delete_unmatched_tokens' + #... + #} + } + elsif ( $var eq 'spacecommand' ) { + &die("No $val function") unless eval "defined &$val"; + } +#18........... + }, }; my $ntests = 0 + keys %{$rtests};