From cfc2e1f3841785ee7466240913f6b13797fb4760 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Thu, 20 Feb 2020 13:56:53 -0500 Subject: fixed compile time slice bug --- eval.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/eval.c b/eval.c index 865d16e..3d72f7b 100644 --- a/eval.c +++ b/eval.c @@ -1293,7 +1293,8 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { case BINARY_AT_INDEX: { void *ptr; Type *type; - eval_expr_ptr_at_index(ev, e, &ptr, &type); + if (!eval_expr_ptr_at_index(ev, e, &ptr, &type)) + return false; eval_deref(v, ptr, type); } break; } @@ -1633,7 +1634,7 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { assert(s->to->type.kind == TYPE_BUILTIN); to = val_to_u64(&tov, s->to->type.builtin); } else { - to = n - 1; + to = n; } /* TODO: is this the best check? (Go also checks if from > to) */ if (to > n) { @@ -1641,12 +1642,10 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { return false; } if (from < to) { - void *ptr1 = NULL, *ptr2 = NULL; - if (!eval_val_ptr_at_index(e->where, &ofv, from, of_type, &ptr1, NULL)) - return false; - if (!eval_val_ptr_at_index(e->where, &ofv, to, of_type, &ptr2, NULL)) + void *ptr_start = NULL; + if (!eval_val_ptr_at_index(e->where, &ofv, from, of_type, &ptr_start, NULL)) return false; - v->slice.data = ptr1; + v->slice.data = ptr_start; v->slice.n = (I64)(to - from); } else { v->slice.data = NULL; -- cgit v1.2.3