Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Nov 2015 17:06:17 +0300
From:      Andrey Chernov <ache@freebsd.org>
To:        Baptiste Daroussin <bapt@freebsd.org>
Cc:        Ed Schouten <ed@nuxi.nl>, Jilles Tjoelker <jilles@stack.nl>, "Sergey V. Dyatko" <sergey.dyatko@gmail.com>, FreeBSD Current <freebsd-current@freebsd.org>
Subject:   Re: /bin/ls formatting broken for non-C(?) locales
Message-ID:  <5655C059.8010701@freebsd.org>
In-Reply-To: <20151125135059.GC77370@ivaldir.etoilebsd.net>
References:  <20151120104253.GA21071@ivaldir.etoilebsd.net> <20151120110212.GB21071@ivaldir.etoilebsd.net> <20151120122352.GA5751@stack.nl> <20151121003541.GF21071@ivaldir.etoilebsd.net> <CABh_MK=cz-zB7krcnKjhqfW9VnwjSmuaZ9%2BAETQiLy3AsHq_vw@mail.gmail.com> <5650DACA.2090501@freebsd.org> <20151125001513.GC70014@ivaldir.etoilebsd.net> <56550F69.8050609@freebsd.org> <20151125125325.GB77370@ivaldir.etoilebsd.net> <5655B8D9.8060805@freebsd.org> <20151125135059.GC77370@ivaldir.etoilebsd.net>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--KtN2d2mgJj9oEFl65Wthe7ha4Eg9s1gQf
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

On 25.11.2015 16:51, Baptiste Daroussin wrote:
> wcslcat works like strlcat:
> to quote the manpage:
> "It will append at most dstsize - strlen(dst) - 1 characters."
> So here with your version it will be n - wcslen(wab_months[i]) -1
> which won't fit what we want to do.
>=20
> btw that makes me figure out that what I want is wcsncat because we do =
care to
> make sure we have appended the right number of spaces at the end of the=

> abbreviated month based on character width, not the on the len of the w=
ide
> string
>=20
> so I changed it
>=20
> if ((n =3D max_month_width - wab_months_width[i]) > 0)
>     wcsncat(wab_months[i], L"     "/* MAX_ABMON_WIDTH */, n);

Sorry, I initially mean wcsncat() functionality here, wcslcat() is
sneaked in due to wrong memorizing.

About width counting and fallback...
Without attempt to nicely truncate data damaged by unknown way the code
will be simpler. Instead all that loop adding width one by one wchar, jus=
t:

width =3D wcswidth(wab_months[i], MAX_ABMON_WIDTH);
if (width =3D=3D -1) {
    max_month_width =3D -1;
    return;
}
wab_months_width[i] =3D width;

About
/* NULL terminate to simplify padding later */
wab_months[i][j] =3D L'\0';
You don't need it, mbstowcs() null-terminates result, if there is a room.=

BTW, array size looks suspicious:
static wchar_t wab_months[12][MAX_ABMON_WIDTH * 2 * MB_LEN_MAX];
what MB_LEN_MAX doing here? This constant is for multiple-bytes encoded,
not for wide chars.

--=20
http://ache.vniz.net/


--KtN2d2mgJj9oEFl65Wthe7ha4Eg9s1gQf
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQEcBAEBCAAGBQJWVcBaAAoJEKUckv0MjfbKjU8IAJLLiGS1ox6gxL80Dj0EWHw4
jXd1mywrMK2uy9mM37X42Wfdp026djIbnsAHdcG9uYlvEDJ6XciHbZqKSrttbWKA
vFfaguvtJ5QAbphllRSF5CqX8o/V6XcgLnldcBOWArQvjQ4hnIBz3Uh1EdGIJSDu
/4u2YLBW2GC3lG0+KqvL/C4QSzFfUUIB+ScyiruK/5eRO4PCOB8/ZAbAiyp7Jq8S
l1J8QED//28UUIKb7EEE8aeOWsf+Kv6EjaZu5tfTfCn73gi9EmqDgLyJiPeRlOce
HNmNo13UXhMrXB8e1L4cieq23NgS4g9zD2AmIjrRmyEnSxgaX1xEu7qXbHbin6w=
=wvIN
-----END PGP SIGNATURE-----

--KtN2d2mgJj9oEFl65Wthe7ha4Eg9s1gQf--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5655C059.8010701>