From 4217c2ccd68699fcdaad9dadc252becd1e672294 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sat, 2 May 2015 13:46:34 +0200 Subject: [PATCH 1/4] - Fixed a very old bug in LookupLevelName code. If the map name neither matched 'ExMy', 'MAPxy' or 'LEVELxy', 'checkstring' was left uninitialized before using as argument to 'strstr', leading to undefined results. Spotted with Valgrind. --- src/g_mapinfo.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/g_mapinfo.cpp b/src/g_mapinfo.cpp index 4d7b3c7d2..d26d2f45b 100644 --- a/src/g_mapinfo.cpp +++ b/src/g_mapinfo.cpp @@ -312,6 +312,10 @@ FString level_info_t::LookupLevelName() { mysnprintf (checkstring, countof(checkstring), "%d: ", atoi(&MapName[5])); } + else + { + checkstring[0] = '\0'; + } thename = strstr (lookedup, checkstring); if (thename == NULL) { From 353ace8be77d45b11708e054fb0edeb25c9ee4f0 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sat, 2 May 2015 14:18:52 +0200 Subject: [PATCH 2/4] - Improve the code readability in LookupLevelName. --- src/g_mapinfo.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/g_mapinfo.cpp b/src/g_mapinfo.cpp index d26d2f45b..5a39d7dbb 100644 --- a/src/g_mapinfo.cpp +++ b/src/g_mapinfo.cpp @@ -314,10 +314,11 @@ FString level_info_t::LookupLevelName() } else { + // make sure nothing is stripped. checkstring[0] = '\0'; } thename = strstr (lookedup, checkstring); - if (thename == NULL) + if (thename == NULL || thename == lookedup) { thename = lookedup; } From 6639f871c6fcb0386c5791edcf73c1f927b1241b Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Sun, 3 May 2015 17:55:01 -0500 Subject: [PATCH 3/4] - Fixed A_SetRipMin/Max not working properly. --- src/thingdef/thingdef_codeptr.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 23a6f58cf..6ac0f115b 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -5895,8 +5895,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfHigherOrLower) // // A_SetRipperLevel(int level) // -// Sets the ripper level/requirement of the calling actor. -// Also sets the minimum and maximum levels to rip through. +// Sets the ripper level of the calling actor. //=========================================================================== DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetRipperLevel) { @@ -5909,26 +5908,24 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetRipperLevel) // // A_SetRipMin(int min) // -// Sets the ripper level/requirement of the calling actor. -// Also sets the minimum and maximum levels to rip through. +// Sets the minimum level a ripper must be in order to rip through this actor. //=========================================================================== DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetRipMin) { ACTION_PARAM_START(1); - ACTION_PARAM_INT(min, 1); + ACTION_PARAM_INT(min, 0); self->RipLevelMin = min; } //=========================================================================== // -// A_SetRipMin(int min) +// A_SetRipMax(int max) // -// Sets the ripper level/requirement of the calling actor. -// Also sets the minimum and maximum levels to rip through. +// Sets the minimum level a ripper must be in order to rip through this actor. //=========================================================================== DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetRipMax) { ACTION_PARAM_START(1); - ACTION_PARAM_INT(max, 1); + ACTION_PARAM_INT(max, 0); self->RipLevelMax = max; } From 6f0caee4babaa517281cdb44b7d0c4b86b4bc917 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 4 May 2015 08:55:31 +0200 Subject: [PATCH 4/4] - fixed: Searching for tag 0 was no longer possible. The new tag manager considers tag 0 'untagged' and won't create entries in its tag list for it, so the normal search algorithm can not find any such sector. It now uses a linear search over all sectors instead, if tag 0 is looked for. --- src/p_tags.cpp | 13 ++++++++++++- src/p_tags.h | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/p_tags.cpp b/src/p_tags.cpp index e773b691f..851c4ee94 100644 --- a/src/p_tags.cpp +++ b/src/p_tags.cpp @@ -309,13 +309,24 @@ int FSectorTagIterator::Next() ret = start; start = -1; } - else + else if (searchtag != 0) { while (start >= 0 && tagManager.allTags[start].tag != searchtag) start = tagManager.allTags[start].nexttag; if (start == -1) return -1; ret = tagManager.allTags[start].target; start = tagManager.allTags[start].nexttag; } + else + { + // with the tag manager, searching for tag 0 has to be different, because it won't create entries for untagged sectors. + while (start < numsectors && tagManager.SectorHasTags(start)) + { + start++; + } + if (start == numsectors) return -1; + ret = start; + start++; + } return ret; } diff --git a/src/p_tags.h b/src/p_tags.h index 2195821c1..75d397d8d 100644 --- a/src/p_tags.h +++ b/src/p_tags.h @@ -79,7 +79,7 @@ public: FSectorTagIterator(int tag) { searchtag = tag; - start = tagManager.TagHashFirst[((unsigned int)tag) % FTagManager::TAG_HASH_SIZE]; + start = tag == 0 ? 0 : tagManager.TagHashFirst[((unsigned int)tag) % FTagManager::TAG_HASH_SIZE]; } // Special constructor for actions that treat tag 0 as 'back of activation line'