summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-03-12 17:09:39 -0500
committerTavian Barnes <tavianator@gmail.com>2010-03-12 17:09:39 -0500
commit17f12a717ffea58b430affff4951c6527189c990 (patch)
treef2eb880c4843488c24e10557d9ad894caec6cce5
parent0b2d17d4e1fc42dddfa70113779d240603979af1 (diff)
downloaddimension-17f12a717ffea58b430affff4951c6527189c990.tar.xz
Check for strdup() failures.
-rw-r--r--dimension/lexer.l13
-rw-r--r--dimension/tokenize.c5
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;
}