From 436539a700cfa01df2abceaf4e7d7de5b613df4c Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 6 Apr 2007 20:35:38 +0000 Subject: [PATCH] Melchior found a bug with negative values in default function arguments --- simgear/nasal/codegen.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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); } -- 2.39.5