]> Savannah Git Hosting - gnulib.git/commitdiff
mbsinit: Don't crash for a NULL argument.
authorBruno Haible <bruno@clisp.org>
Sun, 13 Feb 2011 17:04:55 +0000 (18:04 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 13 Feb 2011 17:04:55 +0000 (18:04 +0100)
* lib/mbsinit.c (mbsinit): When the argument is NULL, return 1.
* tests/test-mbsinit.c (mbsinit): Check this behaviour.

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

index 68ffd30abb99cb8e446db7365f04d10648190fd1..3382c603366280fe0be9d32c803aa7e5df9f1b1a 100644 (file)
--- 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__.
index c08695ce24666dee5d46b37573108c7d71c791d5..869c0a6ab9e542c372a17282e1ee70df124f0ea6 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 d2d98b2dec41ed069dcab83b2e7603304ebdc20a..2cc2924ed5c6c448d88141195e307b4138843226 100644 (file)
@@ -32,6 +32,8 @@ main (int argc, char *argv[])
 {
   static mbstate_t state;
 
+  ASSERT (mbsinit (NULL));
+
   ASSERT (mbsinit (&state));
 
   if (argc > 1)