[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#208308: libc6: Still happens, and doesn't actually conform to the manual pages



On Thu, Mar 06, 2008 at 09:42:33PM +0100, Mike Hommey wrote:
> Package: libc6
> Version: 2.7-9
> Followup-For: Bug #208308
> 
> Bug #208308 is the reason for bug #456653. And it shouldn't happen.
> 
> With the following testcase, it happens while it shouldn't, according to
> the manual:
> -----8<-------
> #include <stdio.h>
> #include <locale.h>
> 
> #define STR "²éľÂíɱ²¡¶¾£¬ÖܺèµtÄúµÄ360²»×¨Òµ£¡"
> 
> int main(void) {
> 	char buf[200];
> 	setlocale(LC_ALL, "");
> 	printf("%d\n", snprintf(buf, 150, "%.50s", STR));
> 	return 0;
> }
> ----->8-------
> 
> The manual page has this to say:
>  About precision:
>   An optional precision, in the form of a period (‘.’)  followed by an
>   optional decimal digit string.(...) This gives (...) the maximum
>   number of characters to be printed from a string for s and S
>   conversions.
> 
>  About s:
>   If no l modifier is present: The const char * argument is expected to
>   be a pointer to an array of character type(...)
> 
>   If an l modifier is present: The const wchar_t * argument is expected
>   to be a pointer to an array of wide characters.  Wide characters from
>   the  array  are converted  to  multibyte  characters (...)
> 
> There is no "l" modifier, but still, the string goes through the
> multibyte conversion code, and fails because the string is invalid
> multibyte.

Note, it only works with non UTF-8 locale set in LC_CTYPE or LC_ALL.

Mike



Reply to: