diff --git a/src/backends/regex.c b/src/backends/regex.c index 5fe3aa0b73b2b09536c3effffd0c21c36445930d..f6494fa98afea084ab347511ec0f25dc0e11379c 100644 --- a/src/backends/regex.c +++ b/src/backends/regex.c @@ -184,13 +184,15 @@ void* h_rvm_run__m(HAllocator *mm__, HRVMProg *prog, const uint8_t* input, size_ -void svm_stack_ensure_cap(HAllocator *mm__, HSVMContext *ctx, size_t addl) { +bool svm_stack_ensure_cap(HAllocator *mm__, HSVMContext *ctx, size_t addl) { if (ctx->stack_count + addl >= ctx->stack_capacity) { ctx->stack = mm__->realloc(mm__, ctx->stack, sizeof(*ctx->stack) * (ctx->stack_capacity *= 2)); if (!ctx->stack) { - ctx->error = 1; + return false; } + return true; } + return true; } HParseResult *run_trace(HAllocator *mm__, HRVMProg *orig_prog, HRVMTrace *trace, const uint8_t *input, int len) { @@ -199,7 +201,6 @@ HParseResult *run_trace(HAllocator *mm__, HRVMProg *orig_prog, HRVMTrace *trace, HArena *arena = h_new_arena(mm__, 0); ctx.stack_count = 0; ctx.stack_capacity = 16; - ctx.error = 0; ctx.stack = h_new(HParsedToken*, ctx.stack_capacity); HParsedToken *tmp_res; @@ -207,8 +208,7 @@ HParseResult *run_trace(HAllocator *mm__, HRVMProg *orig_prog, HRVMTrace *trace, for (cur = trace; cur; cur = cur->next) { switch (cur->opcode) { case SVM_PUSH: - svm_stack_ensure_cap(mm__, &ctx, 1); - if (ctx.error) { + if (!svm_stack_ensure_cap(mm__, &ctx, 1)) { goto fail; } tmp_res = a_new(HParsedToken, 1); diff --git a/src/backends/regex.h b/src/backends/regex.h index 5a19b07e9d925fcee090a071ff94bafdfb70380b..0c51fd0971b375860759fde73beebdce98c622e1 100644 --- a/src/backends/regex.h +++ b/src/backends/regex.h @@ -43,7 +43,6 @@ typedef struct HSVMContext_ { HParsedToken **stack; size_t stack_count; // number of items on the stack. Thus stack[stack_count] is the first unused item on the stack. size_t stack_capacity; - char error; } HSVMContext; // These actions all assume that the items on the stack are not