NetDuke32: Add valid_sprite check before dereferencing PN(spriteNum)
This leaded to program abort while using a sanitizer-enabled debug build, not more than 15-20 seconds into E1L1.
As far as I can tell, a deliberate call to this function with sprite number -1 is unique to NetDuke32, and was introduced in 12dadfd5. The valid_sprite
check does not exist in EDuke32.
I used a gcc build based on 9.4.0, and made a RELEASE=0 build. I applied these local changes to Common.mak in order to take advantage of sanitizers:
diff --git a/Common.mak b/Common.mak
index 4e7896edf..d1c43be74 100644
--- a/Common.mak
+++ b/Common.mak
@@ -623,7 +623,8 @@ endif
# for a list of possible ASan and UBsan options.
ASAN_FLAGS := -fsanitize=address -fsanitize=bounds,enum,float-cast-overflow
-ASAN_FLAGS := $(ASAN_FLAGS),signed-integer-overflow,unsigned-integer-overflow
+ASAN_FLAGS := $(ASAN_FLAGS),signed-integer-overflow
+#ASAN_FLAGS := $(ASAN_FLAGS),signed-integer-overflow,unsigned-integer-overflow
ASAN_FLAGS := $(ASAN_FLAGS),undefined,return,null,pointer-overflow,float-divide-by-zero
#ASAN_FLAGS := $(ASAN_FLAGS) -fsanitize-undefined-trap-on-error
@@ -634,10 +635,11 @@ else
ifneq (0,$(CLANG))
COMMONFLAGS += $(ASAN_FLAGS)
- else ifneq (,$(filter 1 2 3 4 5 6,$(GCC_MAJOR)))
- ifneq (,$(filter 0 1,$(GCC_MINOR)))
+ else
+# else ifneq (,$(filter 1 2 3 4 5 6,$(GCC_MAJOR)))
+# ifneq (,$(filter 0 1,$(GCC_MINOR)))
COMMONFLAGS += $(ASAN_FLAGS)
- endif
+# endif
endif
endif