From 0d1973a659324f238bfcf7fa2770112039c41f07 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 23 Aug 2013 21:56:18 -0500 Subject: [PATCH] Make PStruct::AddField() check for duplicates - PStruct::AddField() now checks the symbol table for a symbol of the same name before adding a new field. If the name is in use, it returns NULL. --- src/dobjtype.cpp | 11 ++++++++--- src/dobjtype.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 7877a79db..fdb85a892 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -1414,11 +1414,12 @@ PStruct::PStruct(FName name, DObject *outer) // // PStruct :: AddField // -// Appends a new field to the end of a struct. +// Appends a new field to the end of a struct. Returns either the new field +// or NULL if a symbol by that name already exists. // //========================================================================== -PField *PStruct::AddField(FName name, PType *type) +PField *PStruct::AddField(FName name, PType *type, DWORD flags) { PField *field = new PField(name, type); @@ -1432,8 +1433,12 @@ PField *PStruct::AddField(FName name, PType *type) // its fields. Align = MAX(Align, type->Align); + if (Symbols.AddSymbol(field) == NULL) + { // name is already in use + delete field; + return NULL; + } Fields.Push(field); - Symbols.AddSymbol(field); return field; } diff --git a/src/dobjtype.h b/src/dobjtype.h index c4fdf48b0..0018d38c4 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -467,7 +467,7 @@ public: TArray Fields; PSymbolTable Symbols; - PField *AddField(FName name, PType *type); + PField *AddField(FName name, PType *type, DWORD flags=0); size_t PropagateMark(); protected: