From 9372f8ff1a5dcfbe18cf78f35f006d5567525626 Mon Sep 17 00:00:00 2001 From: toaster Date: Tue, 27 Jun 2023 23:03:05 +0100 Subject: [PATCH 1/3] Conditionset is UINT16, not UINT8 --- src/deh_soc.c | 2 +- src/deh_soc.h | 2 +- src/dehacked.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index eb30c33ed..c9c457383 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -2859,7 +2859,7 @@ static void readcondition(UINT8 set, UINT32 id, char *word2) M_AddRawCondition(set, (UINT8)id, ty, re, x1, x2, stringvar); } -void readconditionset(MYFILE *f, UINT8 setnum) +void readconditionset(MYFILE *f, UINT16 setnum) { char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); char *word = s; diff --git a/src/deh_soc.h b/src/deh_soc.h index cd20b7714..e1d5e9a32 100644 --- a/src/deh_soc.h +++ b/src/deh_soc.h @@ -62,7 +62,7 @@ skincolornum_t get_skincolor(const char *word); void readwipes(MYFILE *f); void readmaincfg(MYFILE *f, boolean mainfile); -void readconditionset(MYFILE *f, UINT8 setnum); +void readconditionset(MYFILE *f, UINT16 setnum); void readunlockable(MYFILE *f, INT32 num); void reademblemdata(MYFILE *f, INT32 num); void readsound(MYFILE *f, INT32 num); diff --git a/src/dehacked.c b/src/dehacked.c index b46805a97..f6ac70fe1 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -453,7 +453,7 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile) ignorelines(f); } else if (i > 0 && i <= MAXCONDITIONSETS) - readconditionset(f, (UINT8)(i-1)); + readconditionset(f, (UINT16)(i-1)); else { deh_warning("Condition set number %d out of range (1 - %d)", i, MAXCONDITIONSETS); From e2669dba0c4d6c5e743fc8f3fe9554112155f91e Mon Sep 17 00:00:00 2001 From: toaster Date: Wed, 28 Jun 2023 12:16:25 +0100 Subject: [PATCH 2/3] Correct readcondition helper function as well --- src/deh_soc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index c9c457383..14dd9a48e 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -2393,7 +2393,7 @@ void readunlockable(MYFILE *f, INT32 num) Z_Free(s); } -static void readcondition(UINT8 set, UINT32 id, char *word2) +static void readcondition(UINT16 set, UINT32 id, char *word2) { INT32 i; char *params[5]; // condition, requirement, extra info, extra info, stringvar From a933e7a08498b998284fd270b7860413a63d6d3e Mon Sep 17 00:00:00 2001 From: toaster Date: Wed, 28 Jun 2023 12:17:41 +0100 Subject: [PATCH 3/3] Provide helpful warning for too-large id counts for ConditionSet Condition# lines --- src/deh_soc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index 14dd9a48e..4846ec4a1 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -2865,7 +2865,7 @@ void readconditionset(MYFILE *f, UINT16 setnum) char *word = s; char *word2; char *tmp; - UINT8 id; + UINT16 id; UINT8 previd = 0; M_ClearConditionSet(setnum); @@ -2902,21 +2902,26 @@ void readconditionset(MYFILE *f, UINT16 setnum) if (fastncmp(word, "CONDITION", 9)) { - id = (UINT8)atoi(word + 9); + id = atoi(word + 9); if (id == 0) { deh_warning("Condition set %d: unknown word '%s'", setnum+1, word); continue; } - else if (previd > id) + if (previd > id) { // out of order conditions can cause problems, so enforce proper order deh_warning("Condition set %d: conditions are out of order, ignoring this line", setnum+1); continue; } - previd = id; + if (id > UINT8_MAX) + { + deh_warning("Condition set %d: too many Condition# types, ignoring this line", setnum+1); + continue; + } + previd = (UINT8)id; - readcondition(setnum, id, word2); + readcondition(setnum, (UINT8)id, word2); } else deh_warning("Condition set %d: unknown word '%s'", setnum, word);