From: Bruno Haible Date: Fri, 2 Jun 2023 23:22:53 +0000 (+0200) Subject: libgrep: Don't crash upon out-of-memory. X-Git-Tag: v0.22~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45318a260ec29ea6d785ca4f3bd72f11345415d3;p=thirdparty%2Fgettext.git libgrep: Don't crash upon out-of-memory. Pinpointed by gcc 13 warning: warning: use of possibly-NULL ‘mb_properties’ where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument] * gettext-tools/libgrep/m-fgrep.c (check_multibyte_string): Check the malloc() return value. --- diff --git a/gettext-tools/libgrep/m-fgrep.c b/gettext-tools/libgrep/m-fgrep.c index 3589675ba..6ae822f6a 100644 --- a/gettext-tools/libgrep/m-fgrep.c +++ b/gettext-tools/libgrep/m-fgrep.c @@ -112,10 +112,14 @@ Fcompile (const char *pattern, size_t pattern_size, static char* check_multibyte_string (const char *buf, size_t buf_size) { - char *mb_properties = (char *) malloc (buf_size); + char *mb_properties; mbstate_t cur_state; int i; + mb_properties = (char *) malloc (buf_size); + if (mb_properties == NULL) + error (exit_failure, 0, _("memory exhausted")); + memset (&cur_state, 0, sizeof (mbstate_t)); memset (mb_properties, 0, sizeof (char) * buf_size); for (i = 0; i < buf_size ;)