Revision | e54692f524c5ada8883afcdd65b2ab998083c3fe (tree) |
---|---|
Zeit | 2018-08-10 23:02:45 |
Autor | Christophe Lyon <christophe.lyon@st.c...> |
Commiter | Waldemar Brodkorb |
mbtowc: Fix non compliant behavior for end of string
Match glibc behavior.
* libc/stdlib/stdlib.c (mbtowc): Fix end of string behavior.
Signed-off-by: Mickaël Guêné <mickael.guene@st.com>
Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
@@ -895,9 +895,13 @@ int mbtowc(wchar_t *__restrict pwc, register const char *__restrict s, size_t n) | ||
895 | 895 | return is_stateful(ENCODING); |
896 | 896 | } |
897 | 897 | |
898 | - if (*s == '\0') | |
898 | + if (*s == '\0') { | |
899 | 899 | /* According to the ISO C 89 standard this is the expected behaviour. */ |
900 | + /* Standard not very clear here, so do like glibc. */ | |
901 | + if (pwc != NULL) | |
902 | + *pwc = L'\0'; | |
900 | 903 | return 0; |
904 | + } | |
901 | 905 | |
902 | 906 | if ((r = mbrtowc(pwc, s, n, &state)) == (size_t) -2) { |
903 | 907 | /* TODO: Should we set an error state? */ |