From 1c867ce5287419be34b6f6db53be5cf9b7e26a14 Mon Sep 17 00:00:00 2001 From: nhmall Date: Fri, 22 Dec 2023 22:30:38 -0500 Subject: [PATCH] another static analyzer bit for mkobj.c src/mkobj.c(419): warning: '((obj2))->oextra->omonst' could be '0' : this does not adhere to the specification for the function 'memcpy'. src/mkobj.c(421): warning: Dereferencing NULL pointer '((obj2))->oextra->omonst'. See line 419 for an earlier location where this can occur The analyzer was not aware that newoextra() sets up an oextra block: if (!obj2->oextra) obj2->oextra = newoextra(); The analyzer was also not aware that newomonst() was setting up a valid OMONST pointer. if (!OMONST(obj2)) newomonst(obj2); Add an assert(has_omonst(obj2)) before copying the content from OMONST(obj1) into OMONST(obj2). --- src/mkobj.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mkobj.c b/src/mkobj.c index 1b381b599..7970ca92c 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -416,6 +416,7 @@ copy_oextra(struct obj *obj2, struct obj *obj1) if (has_omonst(obj1)) { if (!OMONST(obj2)) newomonst(obj2); + assert(has_omonst(obj2)); (void) memcpy((genericptr_t) OMONST(obj2), (genericptr_t) OMONST(obj1), sizeof (struct monst)); OMONST(obj2)->mextra = (struct mextra *) 0;