From 7280149c57ccc23fe2feb1e95c4219c2b60cf39b Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 24 Sep 2014 11:09:43 -0400 Subject: [PATCH] removed usage of strdup --- source/sclpl/lexer.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/sclpl/lexer.c b/source/sclpl/lexer.c index 4523414..ca1b064 100644 --- a/source/sclpl/lexer.c +++ b/source/sclpl/lexer.c @@ -5,6 +5,7 @@ $HeadURL$ */ #include "lexer.h" +#include static lex_tok_t* lexer_translate(mpc_ast_t* p_tok_ast); static lex_tok_t* lexer_punc(mpc_ast_t* p_tok_ast); @@ -17,6 +18,14 @@ static lex_tok_t* lexer_var(mpc_ast_t* p_tok_ast); static lex_tok_t* lex_tok_new(lex_tok_type_t type, void* val); static int read_radix(const mpc_ast_t* t); +static char* lexer_dup(const char* p_old) { + size_t length = strlen(p_old); + char* p_str = (char*)malloc(length+1); + memcpy(p_str, p_old, length); + p_str[length] = '\0'; + return p_str; +} + /* Grammar is auto generated into 'source/grammar.c' */ extern const char Grammar[]; @@ -149,7 +158,7 @@ lex_tok_t* lexer_bool(mpc_ast_t* p_tok_ast) lex_tok_t* lexer_var(mpc_ast_t* p_tok_ast) { - char* p_str = strdup(p_tok_ast->contents); + char* p_str = lexer_dup(p_tok_ast->contents); return lex_tok_new(VAR, p_str); } -- 2.52.0