citrus_euctw's mbrtowc(3) wrongly checked mbstate_t, so can't convert partial character.
Issue #54
closed
this works fine:
#include <assert.h>
#include <limits.h>
#include <locale.h>
#include <string.h>
#include <wchar.h>
int
main(void) {
mbstate_t st;
char *s = "\x8e\xa2\xa1\xa1";
size_t ret;
setlocale(LC_CTYPE, "zh_TW.eucTW");
memset(&st, 0, sizeof(st));
ret = mbrtowc(NULL, s, sizeof(s), &st);
assert(ret == (size_t)4);
}
but this doesn't work:
#include <assert.h>
#include <limits.h>
#include <locale.h>
#include <string.h>
#include <wchar.h>
int
main(void) {
mbstate_t st;
char *s = "\x8e\xa2\xa1\xa1";
size_t ret, len, i;
setlocale(LC_CTYPE, "zh_TW.eucTW");
memset(&st, 0, sizeof(st));
len = strlen(s);
for (i = 0; i < len - 1; ++i) {
ret = mbrtowc(NULL, s, 1, &st);
assert(ret == (size_t)-2);
++s;
}
ret = mbrtowc(NULL, s, 1, &st);
printf("%zd\n", ret);
assert(ret == (size_t)1);
}
Comments (2)
-
reporter -
reporter - changed status to closed
- Log in to comment
BUGFIX: Issue
#54-- citrus_euctw's mbrtowc(3) wrongly checked mbstate_t, so can't convert partial character.→ <<cset 5f7dace506dc>>