mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 23:32:09 +00:00
[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:
parent
9cccb7a4d4
commit
547cae03ae
1 changed files with 14 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue