mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-13 00:24:12 +00:00
Avoid infinite recursion when encoding struct types.
Structures (especially hard-coded ones) can be really nasty as they can refer to themselves. Avoid the recursion by setting the type_def field of the type before doing the recursive encodings in the structure encoder.
This commit is contained in:
parent
7a25283beb
commit
950a3aa83d
1 changed files with 10 additions and 6 deletions
|
@ -184,6 +184,16 @@ qfo_encode_struct (type_t *type)
|
||||||
continue;
|
continue;
|
||||||
num_fields++;
|
num_fields++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size = field_offset (qfot_struct_t, fields[num_fields]);
|
||||||
|
def = qfo_new_encoding (type, size);
|
||||||
|
enc = D_POINTER (qfot_type_t, def);
|
||||||
|
strct = &enc->t.strct;
|
||||||
|
ENC_STR (strct->tag, type->name);
|
||||||
|
strct->num_fields = num_fields;
|
||||||
|
|
||||||
|
type->type_def = def; // avoid infinite recursion
|
||||||
|
|
||||||
if (type->meta != ty_enum) {
|
if (type->meta != ty_enum) {
|
||||||
field_types = alloca (num_fields * sizeof (def_t *));
|
field_types = alloca (num_fields * sizeof (def_t *));
|
||||||
for (i = 0, sym = type->t.symtab->symbols; sym; sym = sym->next) {
|
for (i = 0, sym = type->t.symtab->symbols; sym; sym = sym->next) {
|
||||||
|
@ -196,12 +206,6 @@ qfo_encode_struct (type_t *type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size = field_offset (qfot_struct_t, fields[num_fields]);
|
|
||||||
def = qfo_new_encoding (type, size);
|
|
||||||
enc = D_POINTER (qfot_type_t, def);
|
|
||||||
strct = &enc->t.strct;
|
|
||||||
ENC_STR (strct->tag, type->name);
|
|
||||||
strct->num_fields = num_fields;
|
|
||||||
for (i = 0, sym = type->t.symtab->symbols; sym; sym = sym->next) {
|
for (i = 0, sym = type->t.symtab->symbols; sym; sym = sym->next) {
|
||||||
if (sym->sy_type != sy)
|
if (sym->sy_type != sy)
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue