Handle boundary cases more correctly; mblen(s, 0) and mbtowc(NULL, s, 0)
return -1 regardless of what s points to, mbtowc(&w, s, 1) sets w to a null wide character when s points to a null byte. This seems to be closer to what most other implementations do, but the C99 standard contradicts itself for these cases.
This commit is contained in:
parent
8c847e9020
commit
c5929b304e
@ -47,13 +47,12 @@ mblen(const char *s, size_t n)
|
||||
{
|
||||
const char *e;
|
||||
|
||||
if (s == NULL || *s == '\0')
|
||||
if (s == NULL)
|
||||
/* No support for state dependent encodings. */
|
||||
return (0);
|
||||
|
||||
if (sgetrune(s, n, &e) == _INVALID_RUNE) {
|
||||
errno = EILSEQ;
|
||||
return (s - e);
|
||||
return (-1);
|
||||
}
|
||||
return (e - s);
|
||||
return (*s == '\0' ? 0 : e - s);
|
||||
}
|
||||
|
@ -48,15 +48,14 @@ mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n)
|
||||
const char *e;
|
||||
rune_t r;
|
||||
|
||||
if (s == NULL || *s == '\0')
|
||||
if (s == NULL)
|
||||
/* No support for state dependent encodings. */
|
||||
return (0);
|
||||
|
||||
if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) {
|
||||
errno = EILSEQ;
|
||||
return (s - e);
|
||||
return (-1);
|
||||
}
|
||||
if (pwc != NULL)
|
||||
*pwc = r;
|
||||
return (e - s);
|
||||
return (r == 0 ? 0 : e - s);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user