citrus_euctw's mbrtowc(3) gets incomplete chars should return (size_t)-2 but (size_t)-1.

Issue #49 closed
Takehiko NOZAKI repo owner created an issue

POSIX spec says that:

(size_t)-2 If the next n bytes contribute to an incomplete but potentially valid character, and all n bytes > have been processed (no value is stored). When n has at least the value of the {MB_CUR_MAX} macro, this case can only occur if s points at a sequence of redundant shift > sequences (for implementations with state-dependent encodings).

but LANG=zh_TW.eucTW returns (size_t)-1, try following code.

#include <assert.h>
#include <locale.h>
#include <string.h>
#include <wchar.h>

int
main(void) {
        mbstate_t st;
        wchar_t wc[1];
        size_t ret;
        const char *s = "\xa3\xa4";

        setlocale(LC_CTYPE, "zh_TW.eucTW");
        memset(&st, 0, sizeof(st));
        ret = mbrtowc(wc, s, 1, &st);
        assert(ret == (size_t)-2);
}

Comments (3)

  1. Log in to comment