From: Dale Weiler Date: Mon, 17 Dec 2012 15:38:32 +0000 (+0000) Subject: Fixes, but still crashes because ... I have no clue, there is no reason for this... X-Git-Tag: 0.1.9~84 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e72d656eb86df33e8c9c3f98ae5ca87fd8585653;p=xonotic%2Fgmqcc.git Fixes, but still crashes because ... I have no clue, there is no reason for this to crash. --- diff --git a/ftepp.c b/ftepp.c index 6fff6e0..d3e58df 100644 --- a/ftepp.c +++ b/ftepp.c @@ -1369,6 +1369,13 @@ bool ftepp_preprocess_string(const char *name, const char *str) void ftepp_add_macro(const char *name, const char *value) { char *create = NULL; + + /* use saner path for empty macros */ + if (!value) { + ftepp_add_define("__builtin__", name); + return; + } + vec_upload(create, "#define ", 8); vec_upload(create, name, strlen(name)); vec_push (create, ' '); diff --git a/main.c b/main.c index ca8ff42..1bb9883 100644 --- a/main.c +++ b/main.c @@ -312,13 +312,19 @@ static bool options_parse(int argc, char **argv) { break; case 'D': - if (!(argarg = strchr(argv[0] + 2, '='))) { - con_out("missing = in -D\n"); + if (!strlen(argv[0]+2)) { + con_err("expected name after -D\n"); exit(0); } - *argarg='\0'; /* terminate for name */ - macro.name = util_strdup(argarg); - macro.value = util_strdup(argv[0]+2); + + if (!(argarg = strchr(argv[0] + 2, '='))) { + macro.name = util_strdup(argv[0]+2); + macro.value = NULL; + } else { + *argarg='\0'; /* terminate for name */ + macro.name = util_strdup(argv[0]+2); + macro.value = util_strdup(argarg+1); + } vec_push(ppems, macro); break; @@ -625,18 +631,21 @@ int main(int argc, char **argv) { con_err("failed to initialize parser\n"); retval = 1; goto cleanup; - } else { - size_t i; - for (i = 0; i < vec_size(ppems); ++i) { - ftepp_add_macro(ppems[i].name, ppems[i].value); - mem_d(ppems[i].name); - mem_d(ppems[i].value); - } } } util_debug("COM", "starting ...\n"); + /* add macros */ + for (itr = 0; itr < vec_size(ppems); itr++) { + ftepp_add_macro(ppems[itr].name, ppems[itr].value); + mem_d(ppems[itr].name); + + /* can be null */ + if (ppems[itr].value) + mem_d(ppems[itr].value); + } + if (!vec_size(items)) { FILE *src; char *line;