Skip to content

Commit

Permalink
printf: descriptive error message (#564)
Browse files Browse the repository at this point in the history
* Follow GNU printf command and attempt to show the bad format specifier which caused an error
* Example: "perl printf '%9 -asd'" now reports "printf: invalid format: '%9'" instead of just "internal error"
  • Loading branch information
mknos committed Apr 17, 2024
1 parent 26c385f commit f7af6f8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/printf
Expand Up @@ -74,7 +74,11 @@ sub parse_fmt {
$i++;
} elsif ($f =~ s/\A(\%[0-9\.\-]*[a-zA-Z])//) {
push @fmt, [ 'str', $1 ]; # unsupported
} else {
} else {
if ($f =~ m/\A[^\%]*(\%[\S]+)/) {
warn "$Program: invalid format: '$1'\n";
exit EX_FAILURE;
}
die "internal error";
}
}
Expand Down

0 comments on commit f7af6f8

Please sign in to comment.