Skip to content

Commit

Permalink
Remove undefined behavior caught by LLVM 10 UBSAN.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaelan authored and nicowilliams committed Oct 8, 2023
1 parent 6b6feaf commit c10cbbf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/exec_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ static void stack_init(struct stack* s) {

static void stack_reset(struct stack* s) {
assert(s->limit == 0 && "stack freed while not empty");
char* mem_start = s->mem_end - ( -s->bound + ALIGNMENT);
free(mem_start);
if(s->mem_end != NULL) {
char* mem_start = s->mem_end - ( -s->bound + ALIGNMENT);
free(mem_start);
}
stack_init(s);
}

Expand All @@ -80,7 +82,7 @@ static stack_ptr* stack_block_next(struct stack* s, stack_ptr p) {

static void stack_reallocate(struct stack* s, size_t sz) {
int old_mem_length = -(s->bound) + ALIGNMENT;
char* old_mem_start = s->mem_end - old_mem_length;
char* old_mem_start = (s->mem_end != NULL) ? (s->mem_end - old_mem_length) : NULL;

int new_mem_length = align_round_up((old_mem_length + sz + 256) * 2);
char* new_mem_start = jv_mem_realloc(old_mem_start, new_mem_length);
Expand Down

0 comments on commit c10cbbf

Please sign in to comment.