From: andy Date: Fri, 6 Apr 2007 20:35:38 +0000 (+0000) Subject: Melchior found a bug with negative values in default function arguments X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=436539a700cfa01df2abceaf4e7d7de5b613df4c;p=simgear.git Melchior found a bug with negative values in default function arguments --- diff --git a/simgear/nasal/codegen.c b/simgear/nasal/codegen.c index 1664ca4f..a0fcd91b 100644 --- a/simgear/nasal/codegen.c +++ b/simgear/nasal/codegen.c @@ -152,6 +152,15 @@ static void genEqOp(int op, struct Parser* p, struct Token* t) static int defArg(struct Parser* p, struct Token* t) { if(t->type == TOK_LPAR) return defArg(p, RIGHT(t)); + if(t->type == TOK_MINUS && RIGHT(t) && + RIGHT(t)->type == TOK_LITERAL && !RIGHT(t)->str) + { + /* default arguments are constants, but "-1" parses as two + * tokens, so we have to subset the expression generator for that + * case */ + RIGHT(t)->num *= -1; + return defArg(p, RIGHT(t)); + } return findConstantIndex(p, t); }