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.
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) {
setlocale( LC_ALL, "");
printf( "%d\n", snprintf(buf, 150, "%.50s", STR));
char buf[200];
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.
This is debian bug http:// bugs.debian. org/208308