another static analyzer bit for wield.c
src/wield.c(745): warning: Dereferencing NULL pointer 'obj'.
See line 685 for an earlier location where this can occur
In wield_tool(), the comparisons against uwep were intended
for when uwep wasn't null.
gcc/clang analyzers now have some awareness of obj arg being
notnull for wield_tool() since the extern.h prototypes
were changed to declare that, but other compilers/analyzers
do not necessarily have that information, and this:
'if (obj == uwep)'
would be a match if both were NULL.
This commit is contained in:
14
src/wield.c
14
src/wield.c
@@ -52,10 +52,10 @@
|
||||
* No item may be in more than one of these slots.
|
||||
*/
|
||||
|
||||
static boolean cant_wield_corpse(struct obj *);
|
||||
static int ready_weapon(struct obj *);
|
||||
static int ready_ok(struct obj *);
|
||||
static int wield_ok(struct obj *);
|
||||
static boolean cant_wield_corpse(struct obj *) NONNULLARG1;
|
||||
static int ready_weapon(struct obj *) NO_NNARGS;
|
||||
static int ready_ok(struct obj *) NO_NNARGS;
|
||||
static int wield_ok(struct obj *) NO_NNARGS;
|
||||
|
||||
/* used by will_weld() */
|
||||
/* probably should be renamed */
|
||||
@@ -676,7 +676,7 @@ wield_tool(struct obj *obj,
|
||||
const char *what;
|
||||
boolean more_than_1;
|
||||
|
||||
if (obj == uwep)
|
||||
if (uwep && obj == uwep)
|
||||
return TRUE; /* nothing to do if already wielding it */
|
||||
|
||||
if (!verb)
|
||||
@@ -690,7 +690,7 @@ wield_tool(struct obj *obj,
|
||||
more_than_1 ? "them" : "it");
|
||||
return FALSE;
|
||||
}
|
||||
if (welded(uwep)) {
|
||||
if (uwep && welded(uwep)) {
|
||||
if (flags.verbose) {
|
||||
const char *hand = body_part(HAND);
|
||||
|
||||
@@ -737,7 +737,7 @@ wield_tool(struct obj *obj,
|
||||
if (flags.pushweapon && oldwep && uwep != oldwep)
|
||||
setuswapwep(oldwep);
|
||||
}
|
||||
if (uwep != obj)
|
||||
if (uwep && uwep != obj)
|
||||
return FALSE; /* rewielded old object after dying */
|
||||
/* applying weapon or tool that gets wielded ends two-weapon combat */
|
||||
if (u.twoweap)
|
||||
|
||||
Reference in New Issue
Block a user