From c60d0b9506f12e1a0c68441e7cff67b0c779b0f5 Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Sun, 22 Jan 2023 17:28:13 -0800
Subject: [PATCH] Fix issue with QWKnet hub sub-board mappings when inserting
 new sub-boards

The sub_t.subnum's that were being updated as message areas were being saved to
msgs.ini could not be used as an index into the scfg_t.sub array at this point
(the subnum would be the new index position when the msgs.ini was re-read/loaded)
.

This was not an issue in v3.19 because we just saved the subnum (to msgs.cnf) and
in v3.20, we save the sub's internal code (to msgs.ini) and were using the newly
updated sub_t.subnum to find the corresponding sub_t for that internal code. Since
the subnum is not used now during the save process, no need to update it here
(this reverses part of the commit 11e529d40bca40 from 5 years ago).

This fixes issue #502 - thanks to the irc.synchro.netizens that reported it!
---
 src/sbbs3/scfgsave.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/sbbs3/scfgsave.c b/src/sbbs3/scfgsave.c
index 045b4b0f87..89f40dd791 100644
--- a/src/sbbs3/scfgsave.c
+++ b/src/sbbs3/scfgsave.c
@@ -365,7 +365,6 @@ BOOL write_msgs_cfg(scfg_t* cfg, int backup_level)
 
 	/* Message Sub-boards */
 
-	unsigned int subnum = 0;	/* New sub-board numbering (as saved) */
 	for(unsigned grp = 0; grp < cfg->total_grps; grp++) {
 		for(uint i=0; i<cfg->total_subs; i++) {
 			if(cfg->sub[i]->lname[0] == 0
@@ -377,7 +376,6 @@ BOOL write_msgs_cfg(scfg_t* cfg, int backup_level)
 			SAFEPRINTF2(name, "sub:%s:%s"
 				,cfg->grp[grp]->sname, cfg->sub[i]->code_suffix);
 			str_list_t section = strListInit();
-			cfg->sub[i]->subnum = subnum++;
 			iniSetString(&section, name, "description", cfg->sub[i]->lname, NULL);
 			iniSetString(&section, name, "name", cfg->sub[i]->sname, NULL);
 			iniSetString(&section, name, "qwk_name", cfg->sub[i]->qwkname, NULL);
@@ -506,17 +504,15 @@ BOOL write_msgs_cfg(scfg_t* cfg, int backup_level)
 		strListMerge(&ini, section);
 		free(section);
 		for(uint j=0; j<cfg->qhub[i]->subs; j++) {
-			if(cfg->qhub[i]->sub[j] == NULL)
-				continue;
-			int subnum = cfg->qhub[i]->sub[j]->subnum;
-			if(!is_valid_subnum(cfg, subnum))
+			sub_t* sub = cfg->qhub[i]->sub[j];
+			if(sub == NULL)
 				continue;
 			SAFEPRINTF2(name, "qhubsub:%s:%u", cfg->qhub[i]->id, cfg->qhub[i]->conf[j]);
 			str_list_t section = strListInit();
 			char code[LEN_EXTCODE + 1];
 			SAFEPRINTF2(code,"%s%s"
-				,cfg->grp[cfg->sub[subnum]->grp]->code_prefix
-				,cfg->sub[subnum]->code_suffix);
+				,cfg->grp[sub->grp]->code_prefix
+				,sub->code_suffix);
 			iniSetString(&section, name, "sub", code, NULL);
 			iniSetHexInt(&section, name, "settings", cfg->qhub[i]->mode[j], NULL);
 			strListMerge(&ini, section);
-- 
GitLab