fix a couple of bugs

main
Alan Francis 1 year ago
parent f5fddc4dbb
commit b40e99b48f
  1. 23
      configmodel.c
  2. 3
      sectionstore.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);
}

@ -4,6 +4,7 @@
#include "containers/stringarray.h"
#include "containers/linearray.h"
#include "cregex/pattern.h"
#include "configfile.h"
#include <proto/exec.h>
#include <string.h>
@ -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);

Loading…
Cancel
Save