From 13a0ea225fb89fe1928303faf9fa23afe355ab97 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 12 Mar 2010 17:17:06 -0500 Subject: Check for malloc() failures. --- dimension/lexer.l | 15 +++++++++------ dimension/parse.c | 2 ++ dimension/tokenize.c | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'dimension') diff --git a/dimension/lexer.l b/dimension/lexer.l index 5027d71..4beeee7 100644 --- a/dimension/lexer.l +++ b/dimension/lexer.l @@ -81,12 +81,15 @@ RETURN(); \ } while (0) -#define STRING_TOKEN() \ - do { \ - NEW_TOKEN(DMNSN_T_STRING); \ - lvalp->value = malloc(string_extent); \ - lvalp->value[0] = '\0'; \ - CALCULATE_COLUMN(); \ +#define STRING_TOKEN() \ + do { \ + NEW_TOKEN(DMNSN_T_STRING); \ + lvalp->value = malloc(string_extent); \ + if (!lvalp->value) \ + dmnsn_error(DMNSN_SEVERITY_HIGH, \ + "Couldn't allocate space for token value."); \ + lvalp->value[0] = '\0'; \ + CALCULATE_COLUMN(); \ } while (0) #define STRCAT(str, len) \ diff --git a/dimension/parse.c b/dimension/parse.c index bc57cef..7897b86 100644 --- a/dimension/parse.c +++ b/dimension/parse.c @@ -519,6 +519,8 @@ dmnsn_vector_promote(dmnsn_astnode astnode, dmnsn_symbol_table *symtable) component.type = DMNSN_AST_INTEGER; long *val = malloc(sizeof(long)); + if (!val) + dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't allocate room for integer."); *val = 0; component.ptr = val; diff --git a/dimension/tokenize.c b/dimension/tokenize.c index bccccc9..2bead0b 100644 --- a/dimension/tokenize.c +++ b/dimension/tokenize.c @@ -226,6 +226,8 @@ dmnsn_include_buffer(int token, dmnsn_token_buffer *prev, 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); + if (!local_include) + dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't allocate space for filename."); strcpy(local_include, localdir); strcat(local_include, "/"); strcat(local_include, include); -- cgit v1.2.3