]> git.donarmstrong.com Git - perltidy.git/commitdiff
update fault check to handle zero length file (c286)
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 5 Oct 2023 04:07:03 +0000 (21:07 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 5 Oct 2023 04:07:03 +0000 (21:07 -0700)
lib/Perl/Tidy/Tokenizer.pm

index 94b0a97ce31329f0f98f066ac050e4aae8cb2061..6b0ae8cb2110332d58bcc53270dd22afbc7bb091 100644 (file)
@@ -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.