summaryrefslogtreecommitdiffstats
path: root/src/lex.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-08-02 00:53:47 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-08-02 00:53:47 +0200
commit546ac7936340312cf272969ff83317ae4d50d2b4 (patch)
tree7ecadca11430c8624d9f80aae7c348fa4d65b969 /src/lex.c
parentb22364f4af3564f0dd9a5f4e150bb09747bd5c4e (diff)
downloadfastd-546ac7936340312cf272969ff83317ae4d50d2b4.tar
fastd-546ac7936340312cf272969ff83317ae4d50d2b4.zip
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).
Diffstat (limited to 'src/lex.c')
-rw-r--r--src/lex.c8
1 files changed, 4 insertions, 4 deletions
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);