From 38d39f292e01551fe30b57583bd79a0d06d59420 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sun, 12 Jun 2016 12:18:14 -0700 Subject: Have MemoryCheck() directly incorporate the error message and exit. Manually inline memory_error() in MemoryCheck(), so that static analyzers know that, if MemoryCheck() sees a null pointer, it exists, and the null pointer isn't subsequently used. Use MemoryCheck() instead of the one place where we manually checked for a null pointer and called memory_error(). Change-Id: Id6b0328cfd17cb14ec9d1e461420896a31573c71 Reviewed-on: https://code.wireshark.org/review/15851 Reviewed-by: Guy Harris --- tools/lemon/lemon.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'tools/lemon') diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index 3798f39742..295f93cf98 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -412,9 +412,9 @@ struct lemon { char *argv0; /* Name of the program */ }; -void memory_error(void); #define MemoryCheck(X) if((X)==0){ \ - memory_error(); \ + fprintf(stderr,"Out of memory. Aborting...\n"); \ + exit(1); \ } /**************** From the file "table.h" *********************************/ @@ -1466,14 +1466,6 @@ void ErrorMsg(const char *filename, int lineno, const char *format, ...){ ** Main program file for the LEMON parser generator. */ -/* Report an out-of-memory condition and abort. This function -** is used mostly by the "MemoryCheck" macro in struct.h -*/ -void memory_error(void){ - fprintf(stderr,"Out of memory. Aborting...\n"); - exit(1); -} - /* Locates the basename in a string possibly containing paths, * including forward-slash and backward-slash delimiters on Windows, * and allocates a new string containing just the basename. @@ -4533,9 +4525,7 @@ void SetSize(int n) char *SetNew(void){ char *s; s = (char*)calloc( size, 1); - if( s==0 ){ - memory_error(); - } + MemoryCheck( s ); return s; } -- cgit v1.2.3