fix a couple of bugs

main
Alan Francis 1 year ago
parent f5fddc4dbb
commit b40e99b48f
  1. 19
      configmodel.c
  2. 3
      sectionstore.c

@ -450,19 +450,32 @@ CONST_STRPTR SectionCanonicalName(SECTIONPTR abstractSection)
{ {
ULONG primaryLength = 0; ULONG primaryLength = 0;
ULONG secondaryLength = 0; ULONG secondaryLength = 0;
ULONG totalLength = 0;
if(section->primary != NULL) if(section->primary != NULL)
{ {
primaryLength = strlen(section->primary); primaryLength = strlen(section->primary);
} }
if(section->secondary != NULL) if(section->secondary != NULL && strlen(section->secondary)>0)
{ {
secondaryLength = strlen(section->secondary); 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); CopyMem(section->primary, result, primaryLength);
if( secondaryLength > 0 )
{
result[primaryLength] = '.'; result[primaryLength] = '.';
CopyMem(section->secondary, result+primaryLength+1, secondaryLength); CopyMem(section->secondary, result+primaryLength+1, secondaryLength);
} }
result[totalLength] = '\0';
}
return result; return result;
} }
@ -544,7 +557,7 @@ CONST_STRPTR VariableSerialize(VARIABLEPTR abstractVariable)
struct Variable* variable = (struct Variable*)abstractVariable; struct Variable* variable = (struct Variable*)abstractVariable;
if( variable != NULL && variable->normalizedKey != NULL && variable->value.stringValue != NULL ) 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); result = AllocVec(size, MEMF_CLEAR);
sprintf(result, "\t%s = %s\n", variable->normalizedKey, variable->value.stringValue); sprintf(result, "\t%s = %s\n", variable->normalizedKey, variable->value.stringValue);
} }

@ -4,6 +4,7 @@
#include "containers/stringarray.h" #include "containers/stringarray.h"
#include "containers/linearray.h" #include "containers/linearray.h"
#include "cregex/pattern.h" #include "cregex/pattern.h"
#include "configfile.h"
#include <proto/exec.h> #include <proto/exec.h>
#include <string.h> #include <string.h>
@ -215,7 +216,7 @@ SECTIONPTR SectionStoreFindOrCreateSection(SECTIONSTOREPTR sectionStore, CONST_S
{ {
// now get the section // now get the section
StringArray canonicalParts = ConfigFileSplitKeyForVar(compoundKey); StringArray canonicalParts = ConfigFileSplitKeyForVar(compoundKey);
SECTIONPTR section = section = SectionStoreGetSection(sectionStore, StringArrayValues(canonicalParts)[0]); SECTIONPTR section = SectionStoreGetSection(sectionStore, StringArrayValues(canonicalParts)[0]);
if( section == NULL ) if( section == NULL )
{ {
StringArray separateParts = ConfigFileSplitKeyCompletely(compoundKey); StringArray separateParts = ConfigFileSplitKeyCompletely(compoundKey);

Loading…
Cancel
Save