From 546ac7936340312cf272969ff83317ae4d50d2b4 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 2 Aug 2014 00:53:47 +0200 Subject: Introduce and use alloc helpers These new helpers will terminate fastd on allocation failures and add some additional convenience (allow strdup with NULL; typesafe new(type) macros). --- src/lex.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/lex.c') diff --git a/src/lex.c b/src/lex.c index 47f6847..1586538 100644 --- a/src/lex.c +++ b/src/lex.c @@ -159,7 +159,7 @@ static inline char current(fastd_lex_t *lex) { /** Returns the current token as a newly allocated string */ static char* get_token(fastd_lex_t *lex) { - return strndup(lex->buffer+lex->start, lex->tok_len); + return fastd_strndup(lex->buffer+lex->start, lex->tok_len); } /** Tries to add the next character to the current token */ @@ -249,7 +249,7 @@ static int parse_string(YYSTYPE *yylval, YYLTYPE *yylloc, fastd_lex_t *lex) { if (lex->needspace) return syntax_error(yylval, lex); - buf = malloc(len); + buf = fastd_alloc(len); while (true) { if (!next(yylloc, lex, true)) { @@ -276,7 +276,7 @@ static int parse_string(YYSTYPE *yylval, YYLTYPE *yylloc, fastd_lex_t *lex) { if (pos >= len) { len *= 2; - buf = realloc(buf, len); + buf = fastd_realloc(buf, len); } buf[pos++] = cur; @@ -444,7 +444,7 @@ static int parse_keyword(YYSTYPE *yylval, YYLTYPE *yylloc, fastd_lex_t *lex) { /** Initializes a new scanner for the given file */ fastd_lex_t* fastd_lex_init(FILE *file) { - fastd_lex_t *lex = calloc(1, sizeof(fastd_lex_t)); + fastd_lex_t *lex = fastd_new0(fastd_lex_t); lex->file = file; advance(lex); -- cgit v1.2.3