]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - misc-utils/cal.c
Merge branch 'PR/libmount-utab-event' of github.com:karelzak/util-linux-work
[thirdparty/util-linux.git] / misc-utils / cal.c
index 3cc5f9d4f2e2e0bf8d647acc15aef88cde1b70f3..e6f4a6e4f3a6a4061c9b4fb007e6106923a6faff 100644 (file)
@@ -320,7 +320,7 @@ int main(int argc, char **argv)
                {"twelve", no_argument, NULL, 'Y'},
                {"help", no_argument, NULL, 'h'},
                {"vertical", no_argument, NULL,'v'},
-               {"column", required_argument, NULL,'c'},
+               {"columns", required_argument, NULL,'c'},
                {NULL, 0, NULL, 0}
        };
 
@@ -433,7 +433,8 @@ int main(int argc, char **argv)
                        if (strcmp(optarg, "auto") == 0)
                                cols = COLUMNS_AUTO;
                        else
-                               cols = strtosize_or_err(optarg, "foo");
+                               cols = strtosize_or_err(optarg,
+                                               _("failed to parse columns"));
                        break;
                case 'V':
                        print_version(EXIT_SUCCESS);
@@ -691,9 +692,9 @@ static void headers_init(struct cal_control *ctl)
        for (i = 0; i < DAYS_IN_WEEK; i++) {
                size_t space_left;
 
-               if (i)
-                       strcat(cur_dh++, " ");
                space_left = sizeof(day_headings) - (cur_dh - day_headings);
+               if (i && space_left)
+                       strncat(cur_dh++, " ", space_left--);
 
                if (space_left <= (ctl->day_width - 1))
                        break;
@@ -1016,8 +1017,8 @@ static void monthly(const struct cal_control *ctl)
 
        rows = (ctl->num_months - 1) / ctl->months_in_row;
        for (i = 0; i < rows + 1 ; i++){
-               if (i == rows)
-                       for (int n = 0; n < ctl->num_months % ctl->months_in_row; n++)
+               if (i == rows && ctl->num_months % ctl->months_in_row > 0)
+                       for (int n = (ctl->num_months % ctl->months_in_row) - 1; n < ctl->months_in_row; n++)
                                ms[n].next = NULL;
 
                for (m = ms; m; m = m->next){
@@ -1295,8 +1296,8 @@ static void __attribute__((__noreturn__)) usage(void)
                "                         %s\n", USAGE_COLORS_DEFAULT);
 
        fputs(USAGE_SEPARATOR, out);
-       printf(USAGE_HELP_OPTIONS(23));
-       printf(USAGE_MAN_TAIL("cal(1)"));
+       fprintf(out, USAGE_HELP_OPTIONS(23));
+       fprintf(out, USAGE_MAN_TAIL("cal(1)"));
 
        exit(EXIT_SUCCESS);
 }