]> granicus.if.org Git - nethack/commit
pacify static analyzer - dog.c
authorPatR <rankin@nethack.org>
Tue, 17 Jan 2023 18:42:00 +0000 (10:42 -0800)
committerPatR <rankin@nethack.org>
Tue, 17 Jan 2023 18:42:00 +0000 (10:42 -0800)
commita9dc8dcd1a91e1b6922147cf01f8172727c21fb6
tree762caf470a5ab2d14e33b6d03942214a791f2cf6
parentbb8c144809db7cce43cbcdbd9681a4adc815243e
pacify static analyzer - dog.c

This is similar to the earlier potential fix that I didn't like,
but I think think one is better.

The analyzer claimed that 'fptr' might be Null inside the switch
case for
|struct permonst *fptr = NULL;
|if (obj->otyp == CORPSE || ...) fptr = &mons[obj->corpsenm];
|switch (obj->otyp) { case CORPSE: ... /* dereference 'fptr' */ }
even though it will always have a non-Null value for otyp==CORPSE.

Make the assignment of 'fptr' unconditional.  mons[NUMMONS] is
valid and won't match any actual monster.  In this case it will
only be used when initializing fptr, never when fptr gets used.
src/dog.c