From 8fc4858a3c3245d4a59cbb65ca5361dc138eb6e5 Mon Sep 17 00:00:00 2001 From: Jesse Ogle Date: Wed, 19 Jun 2013 16:57:03 -0400 Subject: [PATCH] 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> --- cal.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cal.c b/cal.c index b32caf3..1d962fc 100644 --- a/cal.c +++ b/cal.c @@ -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(); }