Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Mar 2009 10:12:29 +0100
From:      Christoph Mallon <christoph.mallon@gmx.de>
To:        David Schultz <das@FreeBSD.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r189804 - head/usr.bin/ncal
Message-ID:  <49BCC67D.70104@gmx.de>
In-Reply-To: <200903141855.n2EItpnp004551@svn.freebsd.org>
References:  <200903141855.n2EItpnp004551@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------000004040405050702070407
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi David!

David Schultz schrieb:
> Author: das
> Date: Sat Mar 14 18:55:51 2009
> New Revision: 189804
> URL: http://svn.freebsd.org/changeset/base/189804
> 
> Log:
>   Multibyte character support for cal(1).
>   
>   PR:		131578
> 
> Modified:
>   head/usr.bin/ncal/ncal.1
>   head/usr.bin/ncal/ncal.c
> 
[...]
> Modified: head/usr.bin/ncal/ncal.c
> ==============================================================================
> --- head/usr.bin/ncal/ncal.c	Sat Mar 14 18:24:15 2009	(r189803)
> +++ head/usr.bin/ncal/ncal.c	Sat Mar 14 18:55:51 2009	(r189804)
[...]
> @@ -532,17 +537,17 @@ printyearb(int y, int jd_flag)
>  	printf("%s\n\n", center(t, s, mw * mpl + mpl));
>  
>  	for (j = 0; j != 12; j += mpl) {
> -		printf("%-*s  ", mw, center(s, year[j].name, mw));
> +		printf("%-*ls  ", mw, wcenter(ws, year[j].name, mw));
>  		if (mpl == 2)
> -			printf("%s\n", center(s, year[j + 1].name, mw));
> +			printf("%ls\n", wcenter(ws, year[j + 1].name, mw));
>  		else
> -			printf("%-*s  %s\n", mw,
> -			    center(s, year[j + 1].name, mw),
> -			    center(t, year[j + 2].name, mw));
> +			printf("%-*ls  %ls\n", mw,
> +			    wcenter(ws, year[j + 1].name, mw),
> +			    wcenter(wt, year[j + 2].name, mw));
>  
>  		if (mpl == 2)
> -			printf(" %s %s %s %s %s %s %s "
> -			       " %s %s %s %s %s %s %.2s\n",
> +			wprintf(L" %ls %ls %ls %ls %ls %ls %ls "
> +				" %ls %ls %ls %ls %ls %ls %.2ls\n",
>  				wds.names[6], wds.names[0], wds.names[1],
>  				wds.names[2], wds.names[3], wds.names[4],
>  				wds.names[5],
[...]

Your changes to ncal are invalid. You are mixing byte and wide output 
functions, which access the same stream (here printf() and wprintf()).
This is not allowed according to C99 ยง17.9.2:5:
"Byte input/output functions shall not be applied to a wide-oriented 
stream and wide character input/output functions shall not be applied to 
a byte-oriented stream. [...]"
(The first access of a stream with a byte/wide oriented function makes 
it byte/wide oriented)
With FreeBSD's current implementation of output functions this 
accidently works, but you should not rely on this. For example with 
glibc's implementation it fails.
Attached is a patch, which changes all wprintf()s back to printf().

	Christoph

--------------000004040405050702070407
Content-Type: text/plain;
 name="ncal.diff"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="ncal.diff"

SW5kZXg6IG5jYWwuYwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBuY2FsLmMJKFJldmlzaW9uIDE4OTg0
NSkKKysrIG5jYWwuYwkoQXJiZWl0c2tvcGllKQpAQCAtNDQzLDE1ICs0NDMsMTUgQEAKIAlt
dyA9IGpkX2ZsYWcgPyBNT05USF9XSURUSF9CX0ogOiBNT05USF9XSURUSF9COwogCiAJc3dw
cmludGYocywgTUFYX1dJRFRILCBMIiVscyAlZCIsIG1vbnRoLm5hbWUsIHkpOwotCXdwcmlu
dGYoTCIlbHNcbiIsIHdjZW50ZXIodCwgcywgbXcpKTsKKwlwcmludGYoIiVsc1xuIiwgd2Nl
bnRlcih0LCBzLCBtdykpOwogCiAJaWYgKGpkX2ZsYWcpCi0JCXdwcmludGYoTCIgJWxzICVs
cyAlbHMgJWxzICVscyAlbHMgJS4ybHNcbiIsCisJCXByaW50Z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KKwkJCXByaW50ZigiJWxzJWxzJWxzJWxzJWxzJWxz
JWxzICIKIAkJCQkiJWxzJWxzJWxzJWxzJWxzJWxzJWxzICIKIAkJCQkiJWxzJWxzJWxzJWxz
JWxzJWxzJS4ybHNcbiIsCiAJCQkJd2RzLm5hbWVzWzZdLCB3ZHMubmFtZXNbMF0sIHdkcy5u
YW1lc1sxXSwK
--------------000004040405050702070407--



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