Skip to content

Commit

Permalink
cal: deal with warnings (#805)
Browse files Browse the repository at this point in the history
* When temporarily enabling warnings.pm I noticed two patterns which generated a warning
* In get_year(), regex check was done too late after the variable has been treated as a number
* In print_year()/print_year_jd() the month lists being combined might have a less elements; explicitly treat those as empty string
  • Loading branch information
mknos authored Nov 13, 2024
1 parent 8934637 commit 77ce1d4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bin/cal
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ sub print_year_jd {
my @m1 = fmt_month($cal::year, $mon[1], 0);

foreach my $i (0 .. 7) {
$m0[$i] = '' unless defined $m0[$i];
$m1[$i] = '' unless defined $m1[$i];
printf "%-${w}s %-${w}s\n", $m0[$i], $m1[$i];
}
}
Expand All @@ -95,6 +97,9 @@ sub print_year {
my @m2 = fmt_month($cal::year, $mon[2], 0);

foreach my $i (0 .. 7) {
$m0[$i] = '' unless defined $m0[$i];
$m1[$i] = '' unless defined $m1[$i];
$m2[$i] = '' unless defined $m2[$i];
printf "%-${w}s %-${w}s %-${w}s\n", $m0[$i], $m1[$i], $m2[$i];
}
}
Expand Down Expand Up @@ -249,7 +254,7 @@ sub get_month {

sub get_year {
my( $year ) = @_;
if( $year < 1 || $year > 9999 || $year !~ /^\d+$/o ) {
if ($year !~ m/\A[0-9]+\z/ || $year < 1 || $year > 9999) {
print "INVALID YEAR ENTERED.\n";
display_help();
}
Expand Down

0 comments on commit 77ce1d4

Please sign in to comment.