diff options
author | 2008-10-03 11:12:33 -0500 | |
---|---|---|
committer | 2008-10-03 11:12:33 -0500 | |
commit | 879e4d2590b50d63f82c3c3652bc3c7900591f1c (patch) | |
tree | 360150a0a9f7b94f455ace32fc5145898d4c4b2f /dtc-lexer.l | |
parent | 68f98d7b8aa41fab175daf9f1bcb2a5bc22dbc90 (diff) |
Implement and use an xstrdup() function
Many places in dtc use strdup(), but none of them actually check the
return value to see if the implied allocation succeeded. This is a
potential bug, which we fix in the patch below by replacing strdup()
with an xstrdup() which in analogy to xmalloc() will quit with a fatal
error if the allocation fails.
I felt the introduciton of util.[ch] was a better choice
for utility oriented code than directly using srcpos.c
for the new string function.
This patch is a re-factoring of Dave Gibson's similar patch.
Signed-off-by: Jon Loeliger <jdl@freescale.com>
Diffstat (limited to 'dtc-lexer.l')
-rw-r--r-- | dtc-lexer.l | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/dtc-lexer.l b/dtc-lexer.l index 6f8b7dd..35b39ca 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -105,7 +105,7 @@ static int pop_input_file(void); yylloc.file = srcpos_file; yylloc.first_line = yylineno; DPRINT("Label: %s\n", yytext); - yylval.labelref = strdup(yytext); + yylval.labelref = xstrdup(yytext); yylval.labelref[yyleng-1] = '\0'; return DT_LABEL; } @@ -128,7 +128,7 @@ static int pop_input_file(void); <INITIAL>[0-9a-fA-F]+ { yylloc.file = srcpos_file; yylloc.first_line = yylineno; - yylval.literal = strdup(yytext); + yylval.literal = xstrdup(yytext); DPRINT("Literal: '%s'\n", yylval.literal); return DT_LEGACYLITERAL; } @@ -136,7 +136,7 @@ static int pop_input_file(void); <V1>[0-9]+|0[xX][0-9a-fA-F]+ { yylloc.file = srcpos_file; yylloc.first_line = yylineno; - yylval.literal = strdup(yytext); + yylval.literal = xstrdup(yytext); DPRINT("Literal: '%s'\n", yylval.literal); return DT_LITERAL; } @@ -145,7 +145,7 @@ static int pop_input_file(void); yylloc.file = srcpos_file; yylloc.first_line = yylineno; DPRINT("Ref: %s\n", yytext+1); - yylval.labelref = strdup(yytext+1); + yylval.labelref = xstrdup(yytext+1); return DT_REF; } @@ -154,7 +154,7 @@ static int pop_input_file(void); yylloc.first_line = yylineno; yytext[yyleng-1] = '\0'; DPRINT("Ref: %s\n", yytext+2); - yylval.labelref = strdup(yytext+2); + yylval.labelref = xstrdup(yytext+2); return DT_REF; } @@ -162,7 +162,7 @@ static int pop_input_file(void); yylloc.file = srcpos_file; yylloc.first_line = yylineno; DPRINT("Ref: %s\n", yytext+1); - yylval.labelref = strdup(yytext+1); + yylval.labelref = xstrdup(yytext+1); return DT_REF; } @@ -186,7 +186,7 @@ static int pop_input_file(void); yylloc.file = srcpos_file; yylloc.first_line = yylineno; DPRINT("PropNodeName: %s\n", yytext); - yylval.propnodename = strdup(yytext); + yylval.propnodename = xstrdup(yytext); BEGIN_DEFAULT(); return DT_PROPNODENAME; } |