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).
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user