From a70912d3115a0b81480667b35f17efd70d5b5177 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Wed, 9 Nov 2022 11:11:19 +0300 Subject: [PATCH] Fix ini section parsing --- src/config.cc | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/config.cc b/src/config.cc index 719b429..c4903de 100644 --- a/src/config.cc +++ b/src/config.cc @@ -379,10 +379,25 @@ static bool configParseLine(Config* config, char* string) *pch = '\0'; } - // Find opening bracket. - pch = strchr(string, '['); - if (pch != NULL) { - char* sectionKey = pch + 1; + // CE: Original implementation treats any line with brackets as section key. + // The problem can be seen when loading Olympus settings (ddraw.ini), which + // contains the following line: + // + // ```ini + // VersionString=Olympus 2207 [Complete]. + // ``` + // + // It thinks that [Complete] is a start of new section, and puts remaining + // keys there. + + // Skip leading whitespace. + while (isspace(*string)) { + string++; + } + + // Check if it's a section key. + if (*string == '[') { + char* sectionKey = string + 1; // Find closing bracket. pch = strchr(sectionKey, ']');