From e54692f524c5ada8883afcdd65b2ab998083c3fe Mon Sep 17 00:00:00 2001 From: Christophe Lyon Date: Wed, 4 Jul 2018 18:09:19 +0200 Subject: mbtowc: Fix non compliant behavior for end of string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Match glibc behavior. * libc/stdlib/stdlib.c (mbtowc): Fix end of string behavior. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon --- libc/stdlib/stdlib.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libc/stdlib/stdlib.c b/libc/stdlib/stdlib.c index 075e6e5d6..f5936630c 100644 --- a/libc/stdlib/stdlib.c +++ b/libc/stdlib/stdlib.c @@ -895,9 +895,13 @@ int mbtowc(wchar_t *__restrict pwc, register const char *__restrict s, size_t n) return is_stateful(ENCODING); } - if (*s == '\0') + if (*s == '\0') { /* According to the ISO C 89 standard this is the expected behaviour. */ + /* Standard not very clear here, so do like glibc. */ + if (pwc != NULL) + *pwc = L'\0'; return 0; + } if ((r = mbrtowc(pwc, s, n, &state)) == (size_t) -2) { /* TODO: Should we set an error state? */ -- cgit v1.2.3