Fix two crash conditions Ampere found. These are just temporary

patches; my private version has rewritten both of these functions
(ironically fixing these bugs in the process) to handle negative
offsets meaning "from the end".
This commit is contained in:
andy 2005-05-29 16:13:48 +00:00
parent 04c5f2c36a
commit f4b05d46ed
2 changed files with 2 additions and 1 deletions

View File

@ -64,7 +64,7 @@ static naRef stringify(struct Context* ctx, naRef r)
static int checkVec(struct Context* ctx, naRef vec, naRef idx)
{
int i = (int)numify(ctx, idx);
if(i < 0 || i >= vec.ref.ptr.vec->rec->size)
if(i < 0 || !vec.ref.ptr.vec->rec || i >= vec.ref.ptr.vec->rec->size)
ERR(ctx, "vector index out of bounds");
return i;
}

View File

@ -115,6 +115,7 @@ static naRef substr(naContext c, naRef me, int argc, naRef* args)
start = (int)startR.num;
if(naIsNil(lenR)) {
len = naStr_len(src) - start;
if(len < 0) return naNil();
} else {
lenR = naNumValue(lenR);
if(naIsNil(lenR)) return naNil();