From 2b087cb45ae91f90492a935625570d7d42ee3ecb Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 7 Apr 2010 14:26:15 -0400 Subject: New dmnsn_malloc() function, and friends. I'm tired of checking for malloc failures everywhere, considering it never happens. So just bail out whenever it does. A lot of stuff is guaranteed to succeed if it returns now. --- dimension/lexer.l | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'dimension/lexer.l') diff --git a/dimension/lexer.l b/dimension/lexer.l index 77772ae..89dd7fd 100644 --- a/dimension/lexer.l +++ b/dimension/lexer.l @@ -74,20 +74,14 @@ #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."); \ + lvalp->value = dmnsn_strdup(yytext); \ RETURN(); \ } while (0) #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 = dmnsn_malloc(string_extent); \ lvalp->value[0] = '\0'; \ CALCULATE_COLUMN(); \ } while (0) @@ -96,10 +90,7 @@ do { \ if (string_length + len + 1 >= string_length) { \ string_extent = 2*(string_length + len + 1); \ - lvalp->value = realloc(lvalp->value, string_extent); \ - if (!lvalp->value) \ - dmnsn_error(DMNSN_SEVERITY_HIGH, \ - "Couldn't allocate space for token value."); \ + lvalp->value = dmnsn_realloc(lvalp->value, string_extent); \ } \ \ strncpy(lvalp->value + string_length, str, len + 1); \ -- cgit v1.2.3