diff --git a/conffile.cpp b/conffile.cpp index 94983e72..5f437ab4 100644 --- a/conffile.cpp +++ b/conffile.cpp @@ -459,19 +459,21 @@ char *ConfigFile::GetStringDup(const char *key, const char *def){ bool ConfigFile::SetString(const char *key, string val, const char *comment){ set::iterator i; bool ret=false; + bool found; ConfigEntry e(key, val); if(comment && *comment) e.comment = comment; e.used=true; i=data.find(e); - if(i!=data.end()){ + found=(i==data.end()); + if(!found){ e.line=i->line; data.erase(e); sectionSizes.DecreaseSectionSize(e.section); ret=true; } - if((i==data.end() && (!alphaSort || timeSort)) || (!alphaSort && timeSort)) + if((found && (!alphaSort || timeSort)) || (!alphaSort && timeSort)) e.line = linectr++; data.insert(e);