diff options
author | Karel Zak | 2013-06-17 18:08:01 +0200 |
---|---|---|
committer | Karel Zak | 2013-06-17 18:09:49 +0200 |
commit | add1924d5b2a0936202a5d68074d3cf70bcafc8d (patch) | |
tree | 5b08e4528a3b0593772999cb215eb94b083c9af2 | |
parent | libmount: be robust for empty target/source strings (diff) | |
download | kernel-qcow2-util-linux-add1924d5b2a0936202a5d68074d3cf70bcafc8d.tar.gz kernel-qcow2-util-linux-add1924d5b2a0936202a5d68074d3cf70bcafc8d.tar.xz kernel-qcow2-util-linux-add1924d5b2a0936202a5d68074d3cf70bcafc8d.zip |
cal: fix -y output for UTF8
... in the yearly() function is a static buffer where is not space for
multibyte headers. The patch also clean ups function where we
initialize headers.
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | misc-utils/cal.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/misc-utils/cal.c b/misc-utils/cal.c index d6fb32c64..c4ed1d1fe 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -425,22 +425,21 @@ static int leap_year(long year) static void headers_init(int julian) { - int i, wd, spaces = julian ? J_DAY_LEN - 1 : DAY_LEN - 1; + size_t i, wd, spaces = julian ? J_DAY_LEN - 1 : DAY_LEN - 1; char *cur_dh = day_headings; for (i = 0; i < DAYS_IN_WEEK; i++) { - ssize_t space_left; + size_t space_left; wd = (i + weekstart) % DAYS_IN_WEEK; if (i) strcat(cur_dh++, " "); - space_left = - sizeof(day_headings) - (cur_dh - day_headings); + space_left = sizeof(day_headings) - (cur_dh - day_headings); + if (space_left <= spaces) break; - cur_dh += - center_str(nl_langinfo(ABDAY_1 + wd), cur_dh, - space_left, spaces); + cur_dh += center_str(nl_langinfo(ABDAY_1 + wd), cur_dh, + space_left, spaces); } for (i = 0; i < MONTHS_IN_YEAR; i++) @@ -591,7 +590,11 @@ static void yearly(int day, long year, int julian) int col, *dp, i, month, row, which_cal; int maxrow, sep_len, week_len; int days[MONTHS_IN_YEAR][MAXDAYS]; - char *p, lineout[100]; + char *p; + /* three weeks + separators + \0 */ + char lineout[ sizeof(day_headings) + 2 + + sizeof(day_headings) + 2 + + sizeof(day_headings) + 1 ]; if (julian) { maxrow = J_MONTH_COLS; @@ -627,6 +630,7 @@ static void yearly(int day, long year, int julian) snprintf(lineout, sizeof(lineout), "\n%s%*s %s%*s %s\n", day_headings, sep_len, "", day_headings, sep_len, "", day_headings); + my_putstring(lineout); for (row = 0; row < DAYS_IN_WEEK - 1; row++) { p = lineout; |