From: andy Date: Tue, 19 Apr 2005 14:19:46 +0000 (+0000) Subject: Fix clamping of the minimum hash size, because the Melchior discovered X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c50bb90374acf3798d747b6e3c4910646e0593d4;p=simgear.git Fix clamping of the minimum hash size, because the Melchior discovered that the column math goes wacky when lgalloced is allowed to be zero. Augment the find() function to take a starting index. Fix strc() to use a default index of zero. Fix parser precedence of TOK_MINUS, so that "a-b-1" means (a-b)-1 and not a-(b-1). --- diff --git a/simgear/nasal/hash.c b/simgear/nasal/hash.c index 1de3fdf5..3b02bc8f 100644 --- a/simgear/nasal/hash.c +++ b/simgear/nasal/hash.c @@ -54,6 +54,7 @@ static struct HashRec* realloc(struct naHash* hash) struct HashRec *h, *h0 = hash->rec; int lga, cols, need = h0 ? h0->size - h0->dels : MIN_HASH_SIZE; + if(need < MIN_HASH_SIZE) need = MIN_HASH_SIZE; for(lga=0; 1< 1 ? naNumValue(args[1]) : naNum(0); - if(argc < 2 || IS_NIL(idr) || !IS_STR(args[0])) + if(argc < 1 || IS_NIL(idr) || !IS_STR(args[0])) naRuntimeError(c, "bad arguments to strc"); idx = (int)naNumValue(idr).num; if(idx > str->len) naRuntimeError(c, "strc index out of bounds"); @@ -357,20 +357,23 @@ static int match(char* a, char* b, int l) return 1; } -static int find(char* a, int al, char* s, int sl) +static int find(char* a, int al, char* s, int sl, int start) { int i; if(al == 0) return 0; - for(i=0; i 2) start = (int)(naNumValue(args[2]).num); return naNum(find(args[0].ref.ptr.str->data, args[0].ref.ptr.str->len, - args[1].ref.ptr.str->data, args[1].ref.ptr.str->len)); + args[1].ref.ptr.str->data, args[1].ref.ptr.str->len, + start)); } static naRef f_split(naContext ctx, naRef me, int argc, naRef* args) diff --git a/simgear/nasal/parse.c b/simgear/nasal/parse.c index 87c4440b..f69d37b3 100644 --- a/simgear/nasal/parse.c +++ b/simgear/nasal/parse.c @@ -21,7 +21,7 @@ struct precedence { { { TOK_AND }, PREC_BINARY }, { { TOK_EQ, TOK_NEQ }, PREC_BINARY }, { { TOK_LT, TOK_LTE, TOK_GT, TOK_GTE }, PREC_BINARY }, - { { TOK_PLUS, TOK_MINUS, TOK_CAT }, PREC_REVERSE }, + { { TOK_PLUS, TOK_MINUS, TOK_CAT }, PREC_BINARY }, { { TOK_MUL, TOK_DIV }, PREC_BINARY }, { { TOK_MINUS, TOK_NEG, TOK_NOT }, PREC_PREFIX }, { { TOK_LPAR, TOK_LBRA }, PREC_SUFFIX },