summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorerh <erh@NetBSD.org>2000-04-01 19:42:57 +0000
committererh <erh@NetBSD.org>2000-04-01 19:42:57 +0000
commit5aef3fa29b37ba4d8fbe0137b4d044a538b4f56c (patch)
treecb2c63aea63fdb2b93752085876edcaa21bb22b9 /lib/libc/stdlib
parent3b69a8011b0bfda3651f6634c35ca90db12dbed2 (diff)
Make mbstowcs and wcstombs work correctly when handed NULL pointers.
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/multibyte.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/lib/libc/stdlib/multibyte.c b/lib/libc/stdlib/multibyte.c
index b3e67820d39..cd0d1586459 100644
--- a/lib/libc/stdlib/multibyte.c
+++ b/lib/libc/stdlib/multibyte.c
@@ -1,4 +1,4 @@
-/* $NetBSD: multibyte.c,v 1.8 1999/09/20 04:39:40 lukem Exp $ */
+/* $NetBSD: multibyte.c,v 1.9 2000/04/01 19:42:57 erh Exp $ */
/*
* Copyright (c) 1991 The Regents of the University of California.
@@ -38,7 +38,7 @@
#if 0
static char *sccsid = "from: @(#)multibyte.c 5.1 (Berkeley) 2/18/91";
#else
-__RCSID("$NetBSD: multibyte.c,v 1.8 1999/09/20 04:39:40 lukem Exp $");
+__RCSID("$NetBSD: multibyte.c,v 1.9 2000/04/01 19:42:57 erh Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -106,15 +106,22 @@ mbstowcs(pwcs, s, n)
{
int count = 0;
- _DIAGASSERT(pwcs != NULL);
_DIAGASSERT(s != NULL);
if (n != 0) {
- do {
- if ((*pwcs++ = (wchar_t) *s++) == 0)
- break;
- count++;
- } while (--n != 0);
+ if (pwcs != NULL) {
+ do {
+ if ((*pwcs++ = (wchar_t) *s++) == 0)
+ break;
+ count++;
+ } while (--n != 0);
+ } else {
+ do {
+ if (((wchar_t)*s++) == 0)
+ break;
+ count++;
+ } while (--n != 0);
+ }
}
return count;
@@ -129,11 +136,16 @@ wcstombs(s, pwcs, n)
{
int count = 0;
- _DIAGASSERT(s != NULL);
_DIAGASSERT(pwcs != NULL);
- if (s == NULL || pwcs == NULL)
+ if (pwcs == NULL)
return (0);
+ if (s == NULL) {
+ while (*pwcs++ != 0)
+ count++;
+ return(count);
+ }
+
if (n != 0) {
do {
if ((*s++ = (char) *pwcs++) == 0)