Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 May 2016 22:54:35 -0700
From:      Conrad Meyer <cem@FreeBSD.org>
To:        Don Lewis <truckman@freebsd.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r300005 - head/usr.bin/ncal
Message-ID:  <CAG6CVpX-0dDZthcNQqzJrnafx-%2BhOkEKhKNGpu0noGqj__0jDQ@mail.gmail.com>
In-Reply-To: <201605170505.u4H55Uwr091152@repo.freebsd.org>
References:  <201605170505.u4H55Uwr091152@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, May 16, 2016 at 10:05 PM, Don Lewis <truckman@freebsd.org> wrote:
> Author: truckman
> Date: Tue May 17 05:05:30 2016
> New Revision: 300005
> URL: https://svnweb.freebsd.org/changeset/base/300005
>
> Log:
>   swprintf() and apparently wcsftime() want the their output buffer size
>   specified in terms of the the number of wide characters and not
>   sizeof(buffer).
> ...
> Modified: head/usr.bin/ncal/ncal.c
> ==============================================================================
> --- head/usr.bin/ncal/ncal.c    Tue May 17 04:53:21 2016        (r300004)
> +++ head/usr.bin/ncal/ncal.c    Tue May 17 05:05:30 2016        (r300005)
> @@ -642,8 +642,8 @@ monthrangeb(int y, int m, int jd_flag, i
>                                 wprintf(L"%-*ls  ",
>                                     mw, wcenter(ws, year[i].name, mw));
>                         else {
> -                               swprintf(ws, sizeof(ws), L"%-ls %d",
> -                                   year[i].name, M2Y(m + i));
> +                               swprintf(ws, sizeof(ws)/sizeof(ws[0]),

Normally we spell this nitems(ws).

> +                                   L"%-ls %d", year[i].name, M2Y(m + i));
>                                 wprintf(L"%-*ls  ", mw, wcenter(ws1, ws, mw));
>                         }
>                 printf("\n");
> @@ -958,7 +958,7 @@ mkweekdays(struct weekdays *wds)
>
>         for (i = 0; i != 7; i++) {
>                 tm.tm_wday = (i+1) % 7;
> -               wcsftime(buf, sizeof(buf), L"%a", &tm);
> +               wcsftime(buf, sizeof(buf)/sizeof(buf[0]), L"%a", &tm);

This one can be nitems(buf) too.

>                 for (len = 2; len > 0; --len) {
>                         if ((width = wcswidth(buf, len)) <= 2)
>                                 break;
>

Best,
Conrad



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAG6CVpX-0dDZthcNQqzJrnafx-%2BhOkEKhKNGpu0noGqj__0jDQ>