From a709ff9ecdcee695ce9c120ecf17d4ae24a53f1a Mon Sep 17 00:00:00 2001
From: Lactozilla <jp6781615@gmail.com>
Date: Mon, 12 Feb 2024 16:28:32 -0300
Subject: [PATCH] Fix Lua 'searchBlockmap'

---
 src/lua_blockmaplib.c | 11 +++--------
 src/p_maputl.c        |  6 ++----
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/src/lua_blockmaplib.c b/src/lua_blockmaplib.c
index 6b4b6229f..c29eadecc 100644
--- a/src/lua_blockmaplib.c
+++ b/src/lua_blockmaplib.c
@@ -312,17 +312,12 @@ static int lib_searchBlockmap(lua_State *L)
 					continue; // our thing just found itself, so move on
 
 				funcret = lib_searchBlockmap_Objects(L, mobj, itmobj);
-				if (funcret == 2) {
-					lua_pushboolean(L, false);
-					return 1;
-				}
-				else if (funcret == 1)
-					retval = false;
-
-				if (P_MobjWasRemoved(mobj)) {
+				if (funcret == 2 || P_MobjWasRemoved(mobj)) {
 					retval = false;
 					break;
 				}
+				else if (funcret == 1)
+					retval = false;
 			}
 		}
 		while (itmobj != NULL);
diff --git a/src/p_maputl.c b/src/p_maputl.c
index 758a71ca3..82b864715 100644
--- a/src/p_maputl.c
+++ b/src/p_maputl.c
@@ -1095,8 +1095,6 @@ bthingit_t *P_NewBlockThingsIterator(int x1, int y1, int x2, int y2)
 		return NULL;
 
 	block = GetBlockmapBlock(x1, y1);
-	if (!block)
-		return NULL;
 
 	if (freeiters != NULL)
 	{
@@ -1188,12 +1186,12 @@ mobj_t *P_BlockThingsIteratorNext(bthingit_t *it, boolean centeronly)
 							if (!it->dynhash)
 							{
 								it->dynhashcapacity = 50;
-								Z_Calloc(it->dynhashcapacity * sizeof(it->dynhashcapacity), PU_LEVEL, &it->dynhash);
+								Z_Calloc(it->dynhashcapacity * sizeof(*it->dynhash), PU_LEVEL, &it->dynhash);
 							}
 							if (it->dynhashcount == it->dynhashcapacity)
 							{
 								it->dynhashcapacity *= 2;
-								it->dynhash = Z_Realloc(it->dynhash, it->dynhashcapacity * sizeof(it->dynhashcapacity), PU_LEVEL, &it->dynhash);
+								it->dynhash = Z_Realloc(it->dynhash, it->dynhashcapacity * sizeof(*it->dynhash), PU_LEVEL, &it->dynhash);
 							}
 							i = (int)it->dynhashcount;
 							it->dynhashcount++;
-- 
GitLab