From cac634567bb368d3b19e797175443574ece1dbb4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 6 Apr 2015 10:51:28 +0200 Subject: [PATCH] - use a proper FString to hold the name of config sections instead of a buffer tacked onto the actual structure. This is necessary if we want to be able to rename a section. --- src/configfile.cpp | 16 ++++++---------- src/configfile.h | 3 ++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/configfile.cpp b/src/configfile.cpp index 8792175f4..9a1f7bd4d 100644 --- a/src/configfile.cpp +++ b/src/configfile.cpp @@ -138,7 +138,7 @@ FConfigFile &FConfigFile::operator = (const FConfigFile &other) while (fromsection != NULL) { fromentry = fromsection->RootEntry; - tosection = NewConfigSection (fromsection->Name); + tosection = NewConfigSection (fromsection->SectionName); while (fromentry != NULL) { NewConfigEntry (tosection, fromentry->Key, fromentry->Value); @@ -309,7 +309,7 @@ const char *FConfigFile::GetCurrentSection () const { if (CurrentSection != NULL) { - return CurrentSection->Name; + return CurrentSection->SectionName.GetChars(); } return NULL; } @@ -506,7 +506,7 @@ FConfigFile::FConfigSection *FConfigFile::FindSection (const char *name) const { FConfigSection *section = Sections; - while (section != NULL && stricmp (section->Name, name) != 0) + while (section != NULL && section->SectionName.CompareNoCase(name) != 0) { section = section->Next; } @@ -540,19 +540,15 @@ FConfigFile::FConfigEntry *FConfigFile::FindEntry ( FConfigFile::FConfigSection *FConfigFile::NewConfigSection (const char *name) { FConfigSection *section; - char *memblock; section = FindSection (name); if (section == NULL) { - size_t namelen = strlen (name); - memblock = new char[sizeof(*section)+namelen]; - section = ::new(memblock) FConfigSection; + section = new FConfigSection; section->RootEntry = NULL; section->LastEntryPtr = §ion->RootEntry; section->Next = NULL; - memcpy (section->Name, name, namelen); - section->Name[namelen] = 0; + section->SectionName = name; *LastSectionPtr = section; LastSectionPtr = §ion->Next; } @@ -777,7 +773,7 @@ bool FConfigFile::WriteConfigFile () const { fputs (section->Note.GetChars(), file); } - fprintf (file, "[%s]\n", section->Name); + fprintf (file, "[%s]\n", section->SectionName.GetChars()); while (entry != NULL) { if (strpbrk(entry->Value, "\r\n") == NULL) diff --git a/src/configfile.h b/src/configfile.h index 34ab9d56b..31943ccb6 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -93,11 +93,12 @@ private: }; struct FConfigSection { + FString SectionName; FConfigEntry *RootEntry; FConfigEntry **LastEntryPtr; FConfigSection *Next; FString Note; - char Name[1]; // + length of name + //char Name[1]; // + length of name }; FConfigSection *Sections;