all repos — mgba @ 11bf4fdfdad16a2a3b8059d652f41c2c6b2e2581

mGBA Game Boy Advance Emulator

Util: Adding a null value to a Configuration removes the value
Jeffrey Pfau jeffrey@endrift.com
Tue, 04 Nov 2014 23:47:31 -0800
commit

11bf4fdfdad16a2a3b8059d652f41c2c6b2e2581

parent

75557d11b2c2ca18fe5f50f4a62e9275ad71f41c

1 files changed, 6 insertions(+), 2 deletions(-)

jump to
M src/util/configuration.csrc/util/configuration.c

@@ -40,13 +40,17 @@ void ConfigurationSetValue(struct Configuration* configuration, const char* section, const char* key, const char* value) {

struct Table* currentSection = &configuration->root; if (section) { currentSection = HashTableLookup(&configuration->sections, section); - if (!currentSection) { + if (!currentSection && value) { currentSection = malloc(sizeof(*currentSection)); HashTableInit(currentSection, 0, _sectionDeinit); HashTableInsert(&configuration->sections, section, currentSection); } } - HashTableInsert(currentSection, key, strdup(value)); + if (value) { + HashTableInsert(currentSection, key, strdup(value)); + } else { + HashTableRemove(currentSection, key); + } } const char* ConfigurationGetValue(const struct Configuration* configuration, const char* section, const char* key) {