Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Nov 2015 15:35:01 +0100
From:      Baptiste Daroussin <bapt@freebsd.org>
To:        Andrey Chernov <ache@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:  <20151125143501.GD77370@ivaldir.etoilebsd.net>
In-Reply-To: <5655C059.8010701@freebsd.org>
References:  <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> <5655C059.8010701@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--osDK9TLjxFScVI/L
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Nov 25, 2015 at 05:06:17PM +0300, Andrey Chernov wrote:
> 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);
>=20
> Sorry, I initially mean wcsncat() functionality here, wcslcat() is
> sneaked in due to wrong memorizing.
>=20
> 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:
>=20
> 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;
>=20
> 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.

right if should be only set on the month we do truncate to MAX_ABMON_WIDTH

> 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.
Bad copy/paste sorry it should be "MAX_ABMON_WIDTH * 2"


I will fix
Bapt

--osDK9TLjxFScVI/L
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iEYEARECAAYFAlZVxxQACgkQ8kTtMUmk6Ew2vwCeLMpD5ywcJ5NwcACp2z5KBQqc
9P4An0Tl5OqHCamir7yJ8WV41cGHrzax
=u5m3
-----END PGP SIGNATURE-----

--osDK9TLjxFScVI/L--



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