Skip to content

Commit

Permalink
CodeQL corrections (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
smaludzi authored May 6, 2024
1 parent 7da78d7 commit aa4a87b
Show file tree
Hide file tree
Showing 16 changed files with 322 additions and 281 deletions.
16 changes: 8 additions & 8 deletions back/bytecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,13 +1481,13 @@ void bytecode_func_addr(bytecode_list * code)
bytecode_list_node * node = code->tail;
while (node != NULL)
{
bytecode * code = &node->value;
if (code != NULL)
bytecode * code_value = &node->value;
if (code_value != NULL)
{
if (code->type == BYTECODE_ID_FUNC_FUNC)
if (code_value->type == BYTECODE_ID_FUNC_FUNC)
{
code->type = BYTECODE_ID_FUNC_ADDR;
code->id_func.func_addr = code->id_func.func_value->addr;
code_value->type = BYTECODE_ID_FUNC_ADDR;
code_value->id_func.func_addr = code_value->id_func.func_value->addr;
}
}
node = node->next;
Expand All @@ -1507,10 +1507,10 @@ void bytecode_list_print(bytecode_list * code)

while (node != NULL)
{
bytecode * code = &node->value;
if (code != NULL)
bytecode * code_value = &node->value;
if (code_value != NULL)
{
bytecode_print(code);
bytecode_print(code_value);
}
node = node->next;
}
Expand Down
6 changes: 3 additions & 3 deletions back/fficall.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ char * test_types_get_string()
return "CCC";
}

test_Point p1 = { 10, 20 };
test_Point test_Point_p1 = { 10, 20 };

test_Point * test_types_get_ptr()
{
return &p1;
return &test_Point_p1;
}

void test_types_call(int i, long long l, float f, double d, bool b, char c, char * str, test_Point * ptr, test_Types rec)
Expand Down Expand Up @@ -357,7 +357,7 @@ test_Types test_types_get_rec()
ret.b = false;
ret.c = 'A';
ret.str = "AAA";
ret.ptr = &p1;
ret.ptr = &test_Point_p1;
ret.rec.x = 20;
ret.rec.y = 30;
ret.tple.x = 200;
Expand Down
5 changes: 0 additions & 5 deletions back/nev.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ static int nev_compile_prog_modules(const char * input, program * prog, module_d
{
module_close(prog->module_value);
}
/* module_print(prog->module_value); */
}
}
}
Expand Down Expand Up @@ -193,10 +192,6 @@ int nev_execute(program * prog, vm * machine, object * result)
machine->ip = prog->module_value->code_entry;
}

/*printf("machine->ip %u\n", machine->ip);
bytecode_array_print(prog->module_value->code_arr,
prog->module_value->code_size);*/

return vm_execute(machine, prog, result);
}

Expand Down
12 changes: 6 additions & 6 deletions back/vmffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ static int vm_execute_func_ffi_record_value(vm * machine, mem_ptr rec_addr, unsi
{
unsigned int rec_offset = 0;
mem_ptr rec_ref_addr = gc_get_vec(machine->collector, rec_addr, i);
mem_ptr rec_addr = gc_get_vec_ref(machine->collector, rec_ref_addr);
mem_ptr rec_vec_addr = gc_get_vec_ref(machine->collector, rec_ref_addr);

*offset = rec_offset = vm_execute_func_ffi_align(*offset, type->elements[i]->alignment);
if (rec_addr != nil_ptr)
if (rec_vec_addr != nil_ptr)
{
ret |= vm_execute_func_ffi_record_value(machine, rec_addr, bc.ffi_record.count, type->elements[i], data, offset);
ret |= vm_execute_func_ffi_record_value(machine, rec_vec_addr, bc.ffi_record.count, type->elements[i], data, offset);
}
else
{
Expand Down Expand Up @@ -354,13 +354,13 @@ static mem_ptr vm_execute_func_ffi_record_new(vm * machine, unsigned int count,
break;
case BYTECODE_FUNC_FFI_RECORD:
{
unsigned int rec_offset = 0;
*offset = rec_offset = vm_execute_func_ffi_align(*offset, type->elements[i]->alignment);
unsigned int record_offset = 0;
*offset = record_offset = vm_execute_func_ffi_align(*offset, type->elements[i]->alignment);

mem_ptr rec_addr = vm_execute_func_ffi_record_new(machine, bc.ffi_record.count,
type->elements[i], data , offset);

*offset = rec_offset + type->elements[i]->size;
*offset = record_offset + type->elements[i]->size;

gc_set_vec(machine->collector, rec, i, rec_addr);
}
Expand Down
10 changes: 5 additions & 5 deletions front/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ int array_to_depth_list(expr * value, expr_list_weak * bfs_list)
expr_list_weak_node * node = bfs_list->head;
while (node != NULL)
{
expr * value = node->value;
expr * node_value = node->value;

if (value->type == EXPR_ARRAY &&
value->array.array_value->type == ARRAY_SUB &&
value->array.array_value->elements != NULL)
if (node_value->type == EXPR_ARRAY &&
node_value->array.array_value->type == ARRAY_SUB &&
node_value->array.array_value->elements != NULL)
{
elements_to_depth_list(value->array.array_value->elements,
elements_to_depth_list(node_value->array.array_value->elements,
bfs_list, node->distance + 1);
}

Expand Down
6 changes: 0 additions & 6 deletions front/constred.c
Original file line number Diff line number Diff line change
Expand Up @@ -2013,11 +2013,6 @@ int except_list_constred(except_list * list, int * result)
return 0;
}

int func_constred_ffi(func * value, int * result)
{
return 0;
}

int func_constred_native(func * value, int * result)
{
if (value->body != NULL && value->body->exprs != NULL)
Expand Down Expand Up @@ -2047,7 +2042,6 @@ int func_constred(func * value, int * result)
func_constred_native(value, result);
break;
case FUNC_TYPE_FFI:
func_constred_ffi(value, result);
break;
}

Expand Down
1 change: 0 additions & 1 deletion front/constred.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ int qualifier_list_constred(qualifier_list * list, int * result);
int listcomp_constred(listcomp * value, int * result);
int array_constred(array * value, int * result);
int bind_constred(bind * value, int * result);
int func_constred_ffi(func * value, int * result);
int func_constred_native(func * value, int * result);
int func_constred(func * value, int * result);
int never_constred(never * nev, int * result);
Expand Down
16 changes: 6 additions & 10 deletions front/emit.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ int func_freevar_emit(freevar * value, int stack_level, module * module_value,
bc.id_local.stack_level = stack_level;
bc.id_local.index = value->src.func_value->index;

/* TODO: remove printf("freevar_func %s %d %d\n", value->src.func_value->decl->id, stack_level, value->src.func_value->index); */

bytecode_add(module_value->code, &bc);
break;
}
Expand Down Expand Up @@ -381,8 +379,6 @@ int expr_id_bind_emit(expr * value, int stack_level, module * module_value,
bc.id_local.index = value->id.id_bind_value->index;
bytecode_add(module_value->code, &bc);

/* printf("id %s sl %d index %d\n", value->id.id, stack_level, value->id.id_bind_value->index); */

return 0;
}

Expand Down Expand Up @@ -2858,7 +2854,7 @@ int expr_match_guard_list_emit(match_guard_list * list, int stack_level,
labelA = bytecode_add(module_value->code, &bc);
condA->jump.offset = labelA->addr - condA->addr;

match_guard_list_node * node = node = list->tail;
match_guard_list_node * node = list->tail;
while (node != NULL)
{
match_guard * match_value = node->value;
Expand Down Expand Up @@ -3428,6 +3424,9 @@ int seq_list_emit(seq_list * list, int * stack_level, module * module_value,
}
switch (value->type)
{
case SEQ_TYPE_UNKNOWN:
assert(0);
break;
case SEQ_TYPE_EXPR:
{
expr_emit(value->expr_value, *stack_level, module_value, list_weak, result);
Expand Down Expand Up @@ -3490,8 +3489,6 @@ int seq_list_emit(seq_list * list, int * stack_level, module * module_value,
pop_prev = 0;
}
break;
default:
assert(0);
}
}

Expand Down Expand Up @@ -5147,11 +5144,10 @@ int func_entry_emit(

bc.type = BYTECODE_LABEL;
labelE = bytecode_add(module_value->code, &bc);

bc.type = BYTECODE_UNHANDLED_EXCEPTION;
bytecode_add(module_value->code, &bc);

/* exception_tab_insert(module_value->exctab_value, labelA->addr, labelE->addr); */

exception_tab_insert(module_value->exctab_value, 0, labelE->addr);

return 0;
Expand Down
Loading

0 comments on commit aa4a87b

Please sign in to comment.