From a38e4bbf37c4a77ea65f548dfcf590cf23e73d7e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 13 Feb 2011 18:04:55 +0100 Subject: [PATCH] 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. --- ChangeLog | 6 ++++++ lib/mbsinit.c | 2 +- tests/test-mbsinit.c | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 68ffd30ab..3382c6033 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) -- 2.11.0