From: Bruno Haible Date: Sun, 13 Feb 2011 17:04:55 +0000 (+0100) Subject: mbsinit: Don't crash for a NULL argument. X-Git-Tag: stable/20110216~14 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=6f5e418e5525857ba5c5f72d58fbce720cf30cf1;p=gnulib.git 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. (cherry picked from commit a38e4bbf37c4a77ea65f548dfcf590cf23e73d7e) --- diff --git a/ChangeLog b/ChangeLog index 83f6416ed..8ba516969 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2011-02-13 Bruno Haible + 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 + 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. diff --git a/lib/mbsinit.c b/lib/mbsinit.c index c08695ce2..869c0a6ab 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 d2d98b2de..2cc2924ed 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)