Bugfix for cal when columns specified as 0

cal -c 0 caused an infinite loop. now the number of columns is set to
the number of months when 0 (i.e. the calendars never wrap).

Signed-off-by: Christoph Lohmann <20h@r-36.net>
This commit is contained in:
Jesse Ogle 2013-06-19 16:57:03 -04:00 committed by Christoph Lohmann
parent b10b1da57d
commit 8fc4858a3c

6
cal.c
View File

@ -28,6 +28,8 @@ drawcal(int year, int month, int day, int ncols, int nmons, int fday)
int row = 0;
char *days[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", };
if(!ncols)
ncols = nmons;
while(nmons > 0) {
last = MIN(nmons, ncols);
for(i = 0; i < last; i++) {
@ -179,8 +181,8 @@ main(int argc, char *argv[])
usage();
}
if(ncols < 0 || ncols > MONTHMAX || month < 1 || month > 12 \
|| nmons < 1 || fday < 0 || fday > 6) {
if(ncols < 0 || month < 1 || month > 12 || nmons < 1 \
|| nmons > MONTHMAX || fday < 0 || fday > 6) {
usage();
}