[util] Catch some more cexpr errors

This commit is contained in:
Bill Currie 2021-02-09 19:29:48 +09:00
parent 5535d1f8e6
commit 35f12c36ff
3 changed files with 11 additions and 6 deletions

View file

@ -129,7 +129,7 @@ uexpr
| '(' expr ')' { $$ = $2; }
| NAME '(' opt_arg_list ')' { $$ = function_expr ($1, $3, context); }
| uexpr '.' field { $$ = field_expr ($1, $3, context); }
| uexpr '[' field ']' { $$ = index_expr ($1, $3, context); }
| uexpr '[' expr ']' { $$ = index_expr ($1, $3, context); }
| '+' uexpr %prec UNARY { $$ = $2; }
| '-' uexpr %prec UNARY { $$ = unary_expr ('-', $2, context); }
| '!' uexpr %prec UNARY { $$ = unary_expr ('!', $2, context); }
@ -268,6 +268,9 @@ index_expr (const exprval_t *a, const exprval_t *b, exprctx_t *context)
binop_t *binop;
exprval_t *result = 0;
if (!a || !b) {
return 0;
}
for (binop = a->type->binops; binop->op; binop++) {
if (binop->op == '[' && binop->other == b->type) {
break;

View file

@ -646,14 +646,14 @@ static void
plitem_index (const exprval_t *a, int index, exprval_t *c,
exprctx_t *ctx)
{
__auto_type array = *(plitem_t **) a->type->data;
__auto_type array = *(plitem_t **) a->value;
if (PL_Type (array) != QFArray) {
cexpr_error(ctx, "not an array object");
return;
}
plitem_t *item = PL_ObjectAtIndex (array, index);
exprval_t *val = 0;
exprval_t *val = 0;
if (!item) {
cexpr_error (ctx, "invalid index: %d", index);
} else {
@ -667,7 +667,7 @@ static void
plitem_int (const exprval_t *a, const exprval_t *b, exprval_t *c,
exprctx_t *ctx)
{
int index = *(int *) a->value;
int index = *(int *) b->value;
plitem_index (a, index, c, ctx);
}
@ -675,7 +675,7 @@ static void
plitem_uint (const exprval_t *a, const exprval_t *b, exprval_t *c,
exprctx_t *ctx)
{
int index = *(int *) a->value;
int index = *(unsigned *) b->value;
plitem_index (a, index, c, ctx);
}
@ -683,7 +683,7 @@ static void
plitem_size_t (const exprval_t *a, const exprval_t *b, exprval_t *c,
exprctx_t *ctx)
{
int index = *(int *) a->value;
int index = *(size_t *) b->value;
plitem_index (a, index, c, ctx);
}

View file

@ -49,6 +49,8 @@ cexpr_struct_getfield (const exprval_t *a, const exprval_t *b, exprval_t *c,
val = cmemalloc (ctx->memsuper, sizeof (exprval_t));
val->type = field->type;
val->value = a->value + (ptrdiff_t) field->value;
} else {
cexpr_error (ctx, "%s has no field %s", a->type->name, name);
}
*(exprval_t **) c->value = val;
}