From: andy Date: Tue, 30 Sep 2008 16:48:36 +0000 (+0000) Subject: Fixes for bugs shaken out in the recent push: die properly for nil X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=818359bfd09e493c8d74b7ace8b91f4d229eab67;p=simgear.git Fixes for bugs shaken out in the recent push: die properly for nil indexes in slices. Fix string conversion issue with bare "+" and "-". Fix lexing of exponent expressions such that "1e" is not a number. --- diff --git a/simgear/nasal/code.c b/simgear/nasal/code.c index 11754b20..cf48dc29 100644 --- a/simgear/nasal/code.c +++ b/simgear/nasal/code.c @@ -503,7 +503,7 @@ static int vbound(naContext ctx, naRef v, naRef ir, int end) static void evalSlice(naContext ctx, naRef src, naRef dst, naRef idx) { if(!IS_VEC(src)) ERR(ctx, "cannot slice non-vector"); - naVec_append(dst, naVec_get(src, vbound(ctx, src, idx, 0))); + naVec_append(dst, naVec_get(src, checkVec(ctx, src, idx))); } static void evalSlice2(naContext ctx, naRef src, naRef dst, diff --git a/simgear/nasal/codegen.c b/simgear/nasal/codegen.c index 76050031..d1c05ef6 100644 --- a/simgear/nasal/codegen.c +++ b/simgear/nasal/codegen.c @@ -560,7 +560,7 @@ static void genAssign(struct Parser* p, struct Token* t) static void genSlice(struct Parser* p, struct Token* t) { - if(!t) naParseError(p, "empty slice expression", -1); + if(!t || t->type==TOK_EMPTY) naParseError(p, "empty slice expression", -1); if(t->type == TOK_COLON) { if(LEFT(t)) genExpr(p, LEFT(t)); else emit(p, OP_PUSHNIL); if(RIGHT(t)) genExpr(p, RIGHT(t)); else emit(p, OP_PUSHNIL); diff --git a/simgear/nasal/lex.c b/simgear/nasal/lex.c index 43253746..d3d525c3 100644 --- a/simgear/nasal/lex.c +++ b/simgear/nasal/lex.c @@ -256,20 +256,23 @@ static int lexHexLiteral(struct Parser* p, int index) return i; } +#define ISNUM(c) ((c) >= '0' && (c) <= '9') + static int lexNumLiteral(struct Parser* p, int index) { int len = p->len, i = index; unsigned char* buf = (unsigned char*)p->buf; double d; - if(i+1= '0' && buf[i] <= '9') i++; if(i= '0' && buf[i] <= '9') i++; } - if(i= '0' && (c) <= '9') void naLex(struct Parser* p) { int i = 0; diff --git a/simgear/nasal/string.c b/simgear/nasal/string.c index 65a29526..4855054c 100644 --- a/simgear/nasal/string.c +++ b/simgear/nasal/string.c @@ -185,9 +185,7 @@ static int tonum(unsigned char* s, int len, double* result) int i=0, fraclen=0; double sgn=1, val, frac=0, exp=0; - // Special case, "." is not a number, even though "1." and ".0" are. - if(len == 1 && s[0] == '.') - return 0; + if(len == 1 && (*s=='.' || *s=='-' || *s=='+')) return 0; // Strip off the leading negative sign first, so we can correctly // parse things like -.xxx which would otherwise confuse