X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fnasal%2Fcode.c;h=cf48dc295770eeb9ad4e886eaecc45af6636c9a3;hb=9cbbe5559844317f44744788ddb308101a1e75e9;hp=44ff2a0e099e68ea0739d51a1500aa18e35abbe8;hpb=dd1ea541ecc4403bcea2ca8c60c03971d1f4338f;p=simgear.git diff --git a/simgear/nasal/code.c b/simgear/nasal/code.c index 44ff2a0e..cf48dc29 100644 --- a/simgear/nasal/code.c +++ b/simgear/nasal/code.c @@ -491,18 +491,19 @@ static void evalUnpack(naContext ctx, int count) // FIXME: unify with almost identical checkVec() above static int vbound(naContext ctx, naRef v, naRef ir, int end) { - int i = IS_NIL(ir) ? (end ? -1 : 0) : numify(ctx, ir); - if(i < 0) i += naVec_size(v); - if(i < 0 || i >= naVec_size(v)) + int sz=naVec_size(v), i = IS_NIL(ir) ? (end ? -1 : 0) : numify(ctx, ir); + if(IS_NIL(ir) && !sz) return i; + if(i < 0) i += sz; + if(i < 0 || i >= sz) naRuntimeError(ctx, "slice index %d out of bounds (size: %d)", - i, naVec_size(v)); + i, sz); return i; } 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,