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);