[qfcc] Copy parameter types when registering new function type

This fixes an error that's been lurking for over two years (since I made
parameters unlimited internally). The problem was the array was being
allocated on the stack and a simple struct copy was used to store type
type, resulting in a dangling pointer onto the stack. I'm surprised it
didn't cause more problems.
This commit is contained in:
Bill Currie 2022-04-29 19:18:21 +09:00
parent 9cccb7a4d4
commit 547cae03ae

View file

@ -495,6 +495,20 @@ find_type (type_t *type)
// allocate a new one
check = new_type ();
*check = *type;
if (is_func (type)) {
check->t.func.param_types = 0;
const type_t *t = unalias_type (type);
int num_params = t->t.func.num_params;
if (num_params < 0) {
num_params = ~num_params;
}
if (num_params) {
check->t.func.param_types = malloc (sizeof (type_t *) * num_params);
for (int i = 0; i < num_params; i++) {
check->t.func.param_types[i] = t->t.func.param_types[i];
}
}
}
check->freeable = 0;
chain_type (check);