From owner-freebsd-current@freebsd.org Wed Nov 25 14:35:05 2015 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9ECA9A37335 for ; Wed, 25 Nov 2015 14:35:05 +0000 (UTC) (envelope-from baptiste.daroussin@gmail.com) Received: from mail-wm0-x22e.google.com (mail-wm0-x22e.google.com [IPv6:2a00:1450:400c:c09::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3339A1CD5; Wed, 25 Nov 2015 14:35:05 +0000 (UTC) (envelope-from baptiste.daroussin@gmail.com) Received: by wmuu63 with SMTP id u63so140500422wmu.0; Wed, 25 Nov 2015 06:35:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=VDPlpHPclvqfO6ZOeT7XlNcPtEGSZEpptihwxM3ytNU=; b=MiWq58UsLnuiB29j3jbI3KYTPoWfYvUQjE2TL0sIULY51rs+bV6TznG5LzEzOw6Ar/ QAizYe5Uex0C1DvRQ52cWnl5B4rFwGyS7VxCdZJtxnaRmnGu9pbhAo2K5a684t/Mhrrk +BupP6iWJgWQ0+aaMNF5HmMfUTYvZounUUaTg2cOWd1qTzG1HmY5OoDP1ZWHSYhNuzuJ dOPdOD1g42rPryl1SuUxGjPn6A3+7n/jL8xT9qZptN4plre0ehTFTilYrSgsQCPDJct7 58xE2b/w14scPU0qbFdoGqycDCwLrNpjSB8qFYzg3TPMQyzDobH1u+piy81I4XVgfl61 JwLA== X-Received: by 10.194.192.198 with SMTP id hi6mr43709182wjc.141.1448462103784; Wed, 25 Nov 2015 06:35:03 -0800 (PST) Received: from ivaldir.etoilebsd.net ([2001:41d0:8:db4c::1]) by smtp.gmail.com with ESMTPSA id he3sm23491147wjc.25.2015.11.25.06.35.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Nov 2015 06:35:03 -0800 (PST) Sender: Baptiste Daroussin Date: Wed, 25 Nov 2015 15:35:01 +0100 From: Baptiste Daroussin To: Andrey Chernov Cc: Ed Schouten , Jilles Tjoelker , "Sergey V. Dyatko" , FreeBSD Current Subject: Re: /bin/ls formatting broken for non-C(?) locales Message-ID: <20151125143501.GD77370@ivaldir.etoilebsd.net> References: <20151120122352.GA5751@stack.nl> <20151121003541.GF21071@ivaldir.etoilebsd.net> <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> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="osDK9TLjxFScVI/L" Content-Disposition: inline In-Reply-To: <5655C059.8010701@freebsd.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2015 14:35:05 -0000 --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--