mbsinit: Don't crash for a NULL argument.
authorBruno Haible <bruno@clisp.org>
Sun, 13 Feb 2011 17:04:55 +0000 (18:04 +0100)
committerIan Beckwith <ianb@erislabs.net>
Wed, 16 Feb 2011 23:34:38 +0000 (23:34 +0000)
* lib/mbsinit.c (mbsinit): When the argument is NULL, return 1.
* tests/test-mbsinit.c (mbsinit): Check this behaviour.
(cherry picked from commit a38e4bbf37c4a77ea65f548dfcf590cf23e73d7e)

ChangeLog
lib/mbsinit.c
tests/test-mbsinit.c

index 83f6416..8ba5169 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 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__.
        * lib/stdio.in.h (__attribute__): Remove definition.
        (_GL_ATTRIBUTE_FORMAT, _GL_ATTRIBUTE_FORMAT_PRINTF): New macros.
index c08695c..869c0a6 100644 (file)
@@ -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;
 }
index d2d98b2..2cc2924 100644 (file)
@@ -32,6 +32,8 @@ main (int argc, char *argv[])
 {
   static mbstate_t state;
 
+  ASSERT (mbsinit (NULL));
+
   ASSERT (mbsinit (&state));
 
   if (argc > 1)