From: Steve Hancock Date: Thu, 5 Oct 2023 04:07:03 +0000 (-0700) Subject: update fault check to handle zero length file (c286) X-Git-Tag: 20230912.03~7 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=84aac28f7709aefee8c4240a964d27f94d834dd3;p=perltidy.git update fault check to handle zero length file (c286) --- diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 94b0a97c..6b0ae8cb 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -657,7 +657,7 @@ EOM # the whole input file at once than line-by-line. # Add a terminal newline if needed to keep line count unchanged (c283) - if ( $source_string !~ /\n$/ ) { $source_string .= "\n" } + if ( $source_string && $source_string !~ /\n$/ ) { $source_string .= "\n" } # Remove leading whitespace except newlines $source_string =~ s/^ [^\S\n]+ //gxm; @@ -669,8 +669,11 @@ EOM if ( @trimmed_lines != @{$rinput_lines} ) { # Shouldn't happen - die in DEVEL_MODE and fix + my $ntr = @trimmed_lines; + my $utr = @{$rinput_lines}; DEVEL_MODE - && $self->Fault("trimmed/untrimmed line counts differ\n"); + && $self->Fault( + "trimmed / untrimmed line counts differ: $ntr / $utr\n"); # Otherwise we can safely continue with undefined trimmed lines. They # will be detected and fixed later.