diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-04-07 14:26:15 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-04-07 14:34:52 -0400 |
commit | 2b087cb45ae91f90492a935625570d7d42ee3ecb (patch) | |
tree | a464213b08d04c8c91c8879a84e534f895c84378 /dimension/tokenize.c | |
parent | 7d6663eeb68bf9d0a3dff86128827c0c1d85df69 (diff) | |
download | dimension-2b087cb45ae91f90492a935625570d7d42ee3ecb.tar.xz |
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.
Diffstat (limited to 'dimension/tokenize.c')
-rw-r--r-- | dimension/tokenize.c | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/dimension/tokenize.c b/dimension/tokenize.c index f20f394..b5a72f1 100644 --- a/dimension/tokenize.c +++ b/dimension/tokenize.c @@ -47,10 +47,7 @@ typedef struct dmnsn_token_buffer { static dmnsn_token_buffer * dmnsn_new_token_buffer(int type, dmnsn_token_buffer *prev, const char *filename) { - dmnsn_token_buffer *tbuffer = malloc(sizeof(dmnsn_token_buffer)); - if (!tbuffer) { - dmnsn_error(DMNSN_SEVERITY_HIGH, "Failed to allocate token buffer."); - } + dmnsn_token_buffer *tbuffer = dmnsn_malloc(sizeof(dmnsn_token_buffer)); tbuffer->type = type; tbuffer->buffered = dmnsn_new_array(sizeof(dmnsn_buffered_token)); @@ -222,13 +219,9 @@ dmnsn_include_buffer(int token, dmnsn_token_buffer *prev, dmnsn_assert(inode->type == DMNSN_AST_STRING, "$include has wrong type."); 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 *filename_copy = dmnsn_strdup(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."); + char *local_include = dmnsn_malloc(strlen(localdir) + strlen(include) + 2); strcpy(local_include, localdir); strcat(local_include, "/"); strcat(local_include, include); @@ -823,10 +816,7 @@ dmnsn_yylex_wrapper(dmnsn_parse_item *lvalp, dmnsn_parse_location *llocp, token = buffered.type; 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."); + lvalp->value = dmnsn_strdup(buffered.lval.value); } else { lvalp->value = NULL; } |