diff --git a/configmodel.c b/configmodel.c index 079da53..549675b 100644 --- a/configmodel.c +++ b/configmodel.c @@ -450,18 +450,31 @@ CONST_STRPTR SectionCanonicalName(SECTIONPTR abstractSection) { ULONG primaryLength = 0; ULONG secondaryLength = 0; + ULONG totalLength = 0; if(section->primary != NULL) { primaryLength = strlen(section->primary); } - if(section->secondary != NULL) + if(section->secondary != NULL && strlen(section->secondary)>0) { secondaryLength = strlen(section->secondary); } - result = AllocVec(primaryLength+1+secondaryLength+1, MEMF_CLEAR); + totalLength += primaryLength; + if( secondaryLength > 0 ) + { + totalLength += 1; // '.' + totalLength += secondaryLength; + } + + result = AllocVec(totalLength+1, MEMF_CLEAR); + CopyMem(section->primary, result, primaryLength); - result[primaryLength] = '.'; - CopyMem(section->secondary, result+primaryLength+1, secondaryLength); + if( secondaryLength > 0 ) + { + result[primaryLength] = '.'; + CopyMem(section->secondary, result+primaryLength+1, secondaryLength); + } + result[totalLength] = '\0'; } return result; } @@ -544,7 +557,7 @@ CONST_STRPTR VariableSerialize(VARIABLEPTR abstractVariable) struct Variable* variable = (struct Variable*)abstractVariable; if( variable != NULL && variable->normalizedKey != NULL && variable->value.stringValue != NULL ) { - ULONG size = strlen(variable->normalizedKey) + 3 + strlen(variable->value.stringValue) + 1; + ULONG size = 1 + strlen(variable->normalizedKey) + 3 + strlen(variable->value.stringValue) + 1 + 1; result = AllocVec(size, MEMF_CLEAR); sprintf(result, "\t%s = %s\n", variable->normalizedKey, variable->value.stringValue); } diff --git a/sectionstore.c b/sectionstore.c index 4113af7..d20e4b5 100644 --- a/sectionstore.c +++ b/sectionstore.c @@ -4,6 +4,7 @@ #include "containers/stringarray.h" #include "containers/linearray.h" #include "cregex/pattern.h" +#include "configfile.h" #include #include @@ -215,7 +216,7 @@ SECTIONPTR SectionStoreFindOrCreateSection(SECTIONSTOREPTR sectionStore, CONST_S { // now get the section StringArray canonicalParts = ConfigFileSplitKeyForVar(compoundKey); - SECTIONPTR section = section = SectionStoreGetSection(sectionStore, StringArrayValues(canonicalParts)[0]); + SECTIONPTR section = SectionStoreGetSection(sectionStore, StringArrayValues(canonicalParts)[0]); if( section == NULL ) { StringArray separateParts = ConfigFileSplitKeyCompletely(compoundKey);