From 29aa28b623543b20d55f6ddec77fda52dd925c90 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 28 Jan 2012 10:35:18 +0000 Subject: [PATCH] commands_parser: use safewrapper functions --- Makefile | 2 +- src/commands_parser.c | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index d5020384..f9600c9a 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ include/GENERATED_tokens.h: include/GENERATED_call.h # and once as an object file for i3. src/commands_parser.o: src/commands_parser.c ${HEADERS} ${CMDPARSE_HEADERS} echo "[i3] CC $<" - $(CC) $(CPPFLAGS) $(CFLAGS) -DTEST_PARSER -DLOGLEVEL="((uint64_t)1 << $(shell awk '/$(shell basename $< .c)/ { print NR; exit 0; }' loglevels.tmp))" -o test.commands_parser $< + $(CC) $(CPPFLAGS) $(CFLAGS) -DTEST_PARSER -DLOGLEVEL="((uint64_t)1 << $(shell awk '/$(shell basename $< .c)/ { print NR; exit 0; }' loglevels.tmp))" -o test.commands_parser $< $(LIBS) $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="((uint64_t)1 << $(shell awk '/$(shell basename $< .c)/ { print NR; exit 0; }' loglevels.tmp))" -c -o $@ $< src/cfgparse.yy.o: src/cfgparse.l src/cfgparse.y.o ${HEADERS} diff --git a/src/commands_parser.c b/src/commands_parser.c index 1bb9f0c2..62dba861 100644 --- a/src/commands_parser.c +++ b/src/commands_parser.c @@ -31,7 +31,6 @@ #include #include "all.h" -#include "queue.h" /******************************************************************************* * The data structures used for parsing. Essentially the current state and a @@ -233,7 +232,7 @@ char *parse_command(const char *input) { if (strncasecmp(walk, token->name + 1, strlen(token->name) - 1) == 0) { DLOG("found literal, moving to next state\n"); if (token->identifier != NULL) - push_string(token->identifier, strdup(token->name + 1)); + push_string(token->identifier, sstrdup(token->name + 1)); walk += strlen(token->name) - 1; next_state(token); token_handled = true; @@ -274,7 +273,7 @@ char *parse_command(const char *input) { } } if (walk != beginning) { - char *str = calloc(walk-beginning + 1, 1); + char *str = scalloc(walk-beginning + 1); strncpy(str, beginning, walk-beginning); if (token->identifier) push_string(token->identifier, str); @@ -321,7 +320,7 @@ char *parse_command(const char *input) { * full input, and underline the position where the parser * currently is. */ char *errormessage; - char *possible_tokens = malloc(tokenlen + 1); + char *possible_tokens = smalloc(tokenlen + 1); char *tokenwalk = possible_tokens; for (c = 0; c < ptr->n; c++) { token = &(ptr->array[c]); @@ -346,13 +345,13 @@ char *parse_command(const char *input) { } } *tokenwalk = '\0'; - asprintf(&errormessage, "Expected one of these tokens: %s", - possible_tokens); + sasprintf(&errormessage, "Expected one of these tokens: %s", + possible_tokens); free(possible_tokens); /* Contains the same amount of characters as 'input' has, but with * the unparseable part highlighted using ^ characters. */ - char *position = malloc(len + 1); + char *position = smalloc(len + 1); for (const char *copywalk = input; *copywalk != '\0'; copywalk++) position[(copywalk - input)] = (copywalk >= walk ? '^' : ' '); position[len] = '\0';