From a66f9c6e2e7b9cb6e83632bbe8aed5eda10197ba Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Thu, 10 Nov 2022 17:16:57 -0800
Subject: [PATCH] iniRemoveKey() will now remove all keys matching teh passed
 key name

There shouldn't be multiple keys with the same name in a section, but if there
were, a call to iniRemoveKey() would would only remove the *first* key with
that name. So loop until all the keys with the matching name are removed and
return true only if they were all successfully removed from the specified
section.

This resolved an observed issue with sbbsctrl-windows displaying an error
dialog "Failure writing initialization file: path/to/sbbs.ini" when there
were multiple *Sound keys in a section and the first such key value matched
that same key in the [Global] section: in this case, we try to remove the
duplicate key/value from the non-global section, but that removal was
considered a failure (iniKeyExists returned TRUE) because we only removed
the *first* key with that name (assuming there would be only one). So we
would abort the save entirely and display the error dialog.
---
 src/xpdev/ini_file.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c
index fe8e4d2e24..d12f270336 100644
--- a/src/xpdev/ini_file.c
+++ b/src/xpdev/ini_file.c
@@ -401,13 +401,19 @@ BOOL iniRemoveKey(str_list_t* list, const char* section, const char* key)
 {
 	size_t	i;
 	char*	vp=NULL;
+	BOOL	removed = FALSE;
 
-	i=get_value(*list, section, key, NULL, &vp, /* literals_supported: */FALSE);
+	while(1) {
+		i=get_value(*list, section, key, NULL, &vp, /* literals_supported: */FALSE);
 
-	if(vp==NULL)
-		return(FALSE);
+		if(vp==NULL)
+			return removed;
 
-	return(strListDelete(list,i));
+		if(!strListDelete(list,i))
+			return FALSE;
+		removed = TRUE;
+	}
+	return removed;
 }
 
 BOOL iniRemoveValue(str_list_t* list, const char* section, const char* key)
-- 
GitLab