summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-10-28 08:24:46 +0000
committertjr <tjr@FreeBSD.org>2002-10-28 08:24:46 +0000
commit61b6263e81ed643acb29797a44b7699b8f01123d (patch)
tree89211f3df1b854343a8ab5c55df5f6568856af88 /lib/libc
parente3283252f9faf305c9d6485bf3a3e172fe91bfed (diff)
downloadFreeBSD-src-61b6263e81ed643acb29797a44b7699b8f01123d.zip
FreeBSD-src-61b6263e81ed643acb29797a44b7699b8f01123d.tar.gz
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.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/locale/mblen.c7
-rw-r--r--lib/libc/locale/mbtowc.c7
2 files changed, 6 insertions, 8 deletions
diff --git a/lib/libc/locale/mblen.c b/lib/libc/locale/mblen.c
index a54e051..ad5edb3 100644
--- a/lib/libc/locale/mblen.c
+++ b/lib/libc/locale/mblen.c
@@ -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);
}
diff --git a/lib/libc/locale/mbtowc.c b/lib/libc/locale/mbtowc.c
index a690bec..27bebcf 100644
--- a/lib/libc/locale/mbtowc.c
+++ b/lib/libc/locale/mbtowc.c
@@ -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);
}
OpenPOWER on IntegriCloud