From 17f12a717ffea58b430affff4951c6527189c990 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 12 Mar 2010 17:09:39 -0500 Subject: Check for strdup() failures. --- dimension/lexer.l | 13 ++++++++----- dimension/tokenize.c | 5 +++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/dimension/lexer.l b/dimension/lexer.l index 05c6711..5027d71 100644 --- a/dimension/lexer.l +++ b/dimension/lexer.l @@ -71,11 +71,14 @@ RETURN(); \ } while (0) -#define RETURN_VALUE_TOKEN(token_type) \ - do { \ - NEW_TOKEN(token_type); \ - lvalp->value = strdup(yytext); \ - RETURN(); \ +#define RETURN_VALUE_TOKEN(token_type) \ + do { \ + NEW_TOKEN(token_type); \ + lvalp->value = strdup(yytext); \ + if (!lvalp->value) \ + dmnsn_error(DMNSN_SEVERITY_HIGH, \ + "Couldn't allocate space for token value."); \ + RETURN(); \ } while (0) #define STRING_TOKEN() \ diff --git a/dimension/tokenize.c b/dimension/tokenize.c index 33512ae..bccccc9 100644 --- a/dimension/tokenize.c +++ b/dimension/tokenize.c @@ -222,6 +222,8 @@ dmnsn_include_buffer(int token, dmnsn_token_buffer *prev, const char *include = inode->ptr; char *filename_copy = strdup(filename); + if (!filename_copy) + dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't allocate space for filename."); char *localdir = dirname(filename_copy); char *local_include = malloc(strlen(localdir) + strlen(include) + 2); strcpy(local_include, localdir); @@ -673,6 +675,9 @@ dmnsn_yylex_wrapper(dmnsn_parse_item *lvalp, dmnsn_parse_location *llocp, if (buffered.lval.value) { lvalp->value = strdup(buffered.lval.value); + if (!lvalp->value) + dmnsn_error(DMNSN_SEVERITY_HIGH, + "Couldn't allocate space for token value."); } else { lvalp->value = NULL; } -- cgit v1.2.3