Here's a simpler testcase for this bug courtesy of Jonathan Nieder:
#include <stdio.h> #include <locale.h>
int main(void) { int n;
setlocale(LC_CTYPE, ""); n = printf("%.11s\n", "Author: \277"); perror("printf"); fprintf(stderr, "return value: %d\n", n); return 0; }
Under a C locale that'll do the right thing:
$ LANG=C ./test Author: � printf: Success return value: 10
But not under a UTF-8 locale, since \277 isn't a valid UTF-8 sequence:
$ LANG=en_US.utf8 ./test printf: Invalid or incomplete multibyte or wide character return value: -1
Here's a simpler testcase for this bug courtesy of Jonathan Nieder:
#include <stdio.h>
#include <locale.h>
int main(void)
{
int n;
n = printf("%.11s\n", "Author: \277");
return 0;
}
Under a C locale that'll do the right thing:
$ LANG=C ./test
Author: �
printf: Success
return value: 10
But not under a UTF-8 locale, since \277 isn't a valid UTF-8 sequence:
$ LANG=en_US.utf8 ./test
printf: Invalid or incomplete multibyte or wide character
return value: -1