From: Bruno Haible <bruno@clisp.org>
Date: Sun, 13 Feb 2011 17:04:55 +0000 (+0100)
Subject: mbsinit: Don't crash for a NULL argument.
X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fbuilds%2F20110716030503%2Fgnulib;p=pspp

mbsinit: Don't crash for a NULL argument.

* lib/mbsinit.c (mbsinit): When the argument is NULL, return 1.
* tests/test-mbsinit.c (mbsinit): Check this behaviour.
---

diff --git a/ChangeLog b/ChangeLog
index 68ffd30abb..3382c60336 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-02-13  Bruno Haible  <bruno@clisp.org>
+
+	mbsinit: Don't crash for a NULL argument.
+	* lib/mbsinit.c (mbsinit): When the argument is NULL, return 1.
+	* tests/test-mbsinit.c (mbsinit): Check this behaviour.
+
 2011-02-13  Bruno Haible  <bruno@clisp.org>
 
 	Don't interfere with a program's definition of __attribute__.
diff --git a/lib/mbsinit.c b/lib/mbsinit.c
index c08695ce24..869c0a6ab9 100644
--- a/lib/mbsinit.c
+++ b/lib/mbsinit.c
@@ -43,5 +43,5 @@ mbsinit (const mbstate_t *ps)
 {
   const char *pstate = (const char *)ps;
 
-  return pstate[0] == 0;
+  return pstate == NULL || pstate[0] == 0;
 }
diff --git a/tests/test-mbsinit.c b/tests/test-mbsinit.c
index d2d98b2dec..2cc2924ed5 100644
--- a/tests/test-mbsinit.c
+++ b/tests/test-mbsinit.c
@@ -32,6 +32,8 @@ main (int argc, char *argv[])
 {
   static mbstate_t state;
 
+  ASSERT (mbsinit (NULL));
+
   ASSERT (mbsinit (&state));
 
   if (argc > 1)