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:
parent
b10b1da57d
commit
8fc4858a3c
6
cal.c
6
cal.c
@ -28,6 +28,8 @@ drawcal(int year, int month, int day, int ncols, int nmons, int fday)
|
|||||||
int row = 0;
|
int row = 0;
|
||||||
char *days[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", };
|
char *days[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", };
|
||||||
|
|
||||||
|
if(!ncols)
|
||||||
|
ncols = nmons;
|
||||||
while(nmons > 0) {
|
while(nmons > 0) {
|
||||||
last = MIN(nmons, ncols);
|
last = MIN(nmons, ncols);
|
||||||
for(i = 0; i < last; i++) {
|
for(i = 0; i < last; i++) {
|
||||||
@ -179,8 +181,8 @@ main(int argc, char *argv[])
|
|||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ncols < 0 || ncols > MONTHMAX || month < 1 || month > 12 \
|
if(ncols < 0 || month < 1 || month > 12 || nmons < 1 \
|
||||||
|| nmons < 1 || fday < 0 || fday > 6) {
|
|| nmons > MONTHMAX || fday < 0 || fday > 6) {
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user