changeset 14344:5cdebc45677d

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.
author Bruno Haible <bruno@clisp.org>
date Sun, 13 Feb 2011 18:04:55 +0100
parents 8e4360837451
children 38e1a5ec714d
files ChangeLog lib/mbsinit.c tests/test-mbsinit.c
diffstat 3 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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__.
--- a/lib/mbsinit.c
+++ b/lib/mbsinit.c
@@ -43,5 +43,5 @@
 {
   const char *pstate = (const char *)ps;
 
-  return pstate[0] == 0;
+  return pstate == NULL || pstate[0] == 0;
 }
--- a/tests/test-mbsinit.c
+++ b/tests/test-mbsinit.c
@@ -32,6 +32,8 @@
 {
   static mbstate_t state;
 
+  ASSERT (mbsinit (NULL));
+
   ASSERT (mbsinit (&state));
 
   if (argc > 1)