From 07ef4583ce79d1c5a35e33c629daea0ad91d7d27 Mon Sep 17 00:00:00 2001 From: nhmall Date: Wed, 20 Dec 2023 18:48:50 -0500 Subject: [PATCH] functions passed a chain explicitly NO_NONNULLS Some functions are passed an obj or monst chain, and the callers typically don't check them against 0, so mark them explicitly as NO_NONNULLS (NO_NONNULLS expands to nothing, but it flags that some null arg analysis has been done) --- include/extern.h | 23 +++++++++++++++-------- src/end.c | 2 +- src/mon.c | 2 +- src/questpgr.c | 3 ++- src/save.c | 6 +++--- src/zap.c | 2 +- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/include/extern.h b/include/extern.h index 36ba1f9bd..249e72074 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1104,7 +1104,8 @@ extern int calc_capacity(int); extern int max_capacity(void); extern boolean check_capacity(const char *); extern int inv_cnt(boolean); -extern long money_cnt(struct obj *); +/* sometimes money_cnt(gi.invent) which can be null */ +extern long money_cnt(struct obj *) NO_NONNULLS; extern void spot_checks(coordxy, coordxy, schar); /* ### hacklib.c ### */ @@ -1237,7 +1238,8 @@ extern struct obj *addinv_before(struct obj *, struct obj *) NONNULLARG1; extern struct obj *addinv_nomerge(struct obj *) NONNULLARG1; extern struct obj *hold_another_object(struct obj *, const char *, const char *, const char *) NONNULLARG1; -extern void useupall(struct obj *) NONNULLARG1; +/* sometimes useupall(gi.invent) which can be null */ +extern void useupall(struct obj *) NO_NONNULLS; extern void useup(struct obj *) NONNULLARG1; extern void consume_obj_charge(struct obj *, boolean) NONNULLARG1; extern void freeinv_core(struct obj *) NONNULLARG1; @@ -1266,7 +1268,7 @@ extern int askchain(struct obj **, const char *, int, int(*)(struct obj *), extern void set_cknown_lknown(struct obj *) NONNULLARG1; extern void fully_identify_obj(struct obj *) NONNULLARG1; extern int identify(struct obj *) NONNULLARG1; -extern int count_unidentified(struct obj *); +extern int count_unidentified(struct obj *) NO_NONNULLS; extern void identify_pack(int, boolean); extern void learn_unseen_invent(void); extern void update_inventory(void); @@ -1301,7 +1303,8 @@ extern boolean check_invent_gold(const char *) NONNULLARG1; extern int doorganize(void); extern int adjust_split(void); extern void free_pickinv_cache(void); -extern int count_unpaid(struct obj *); +/* sometimes count_unpaid(gi.invent) which can be null */ +extern int count_unpaid(struct obj *) NO_NONNULLS; extern int count_buc(struct obj *, int, boolean(*)(struct obj *)); extern void tally_BUCX(struct obj *, boolean, int *, int *, int *, int *, int *, int *); @@ -2294,9 +2297,13 @@ extern boolean allow_category(struct obj *) NONNULLARG1; extern boolean is_worn_by_type(struct obj *) NONNULLARG1; extern int ck_bag(struct obj *) NONNULLARG1; extern void removed_from_icebox(struct obj *) NONNULLARG1; -extern void reset_justpicked(struct obj *) NONNULLARG1; -extern int count_justpicked(struct obj *) NONNULLARG1; -extern struct obj *find_justpicked(struct obj *) NONNULLARG1; +/* reset_justpicked() is sometimes passed gi.invent + * which can be null */ +extern void reset_justpicked(struct obj *) NO_NONNULLS; +/* sometimes count_justpicked(gi.invent) which can be null */ +extern int count_justpicked(struct obj *) NO_NONNULLS; +/* sometimes find_justpicked(gi.invent) which can be null */ +extern struct obj *find_justpicked(struct obj *) NO_NONNULLS; extern int pickup(int); extern int pickup_object(struct obj *, long, boolean) NONNULLARG1; extern int query_category(const char *, struct obj *, int, menu_item **, int) NONNULLARG14; @@ -2909,7 +2916,7 @@ extern void maybe_absorb_item(struct monst *, struct obj *, int, int) NONNULLARG extern void mdrop_obj(struct monst *, struct obj *, boolean) NONNULLARG12; extern void mdrop_special_objs(struct monst *) NONNULLARG1; extern void relobj(struct monst *, int, boolean) NONNULLARG1; -extern struct obj *findgold(struct obj *) NONNULLARG1; +extern struct obj *findgold(struct obj *) NO_NONNULLS; /* ### steed.c ### */ diff --git a/src/end.c b/src/end.c index d8637c585..909bd357a 100644 --- a/src/end.c +++ b/src/end.c @@ -26,7 +26,7 @@ static void done_hangup(int); #endif #endif static void disclose(int, boolean); -static void get_valuables(struct obj *); +static void get_valuables(struct obj *) NO_NONNULLS; static void sort_valuables(struct valuable_data *, int); static void artifact_score(struct obj *, boolean, winid); static boolean fuzzer_savelife(int); diff --git a/src/mon.c b/src/mon.c index 1938814ea..e02b4b28f 100644 --- a/src/mon.c +++ b/src/mon.c @@ -32,7 +32,7 @@ static boolean isspecmon(struct monst *); static boolean validspecmon(struct monst *, int); static int wiz_force_cham_form(struct monst *); static struct permonst *accept_newcham_form(struct monst *, int); -static void kill_eggs(struct obj *); +static void kill_eggs(struct obj *) NO_NONNULLS; static void pacify_guard(struct monst *); extern const struct shclass shtypes[]; /* defined in shknam.c */ diff --git a/src/questpgr.c b/src/questpgr.c index 04bb6e719..ba025d962 100644 --- a/src/questpgr.c +++ b/src/questpgr.c @@ -14,7 +14,8 @@ #endif static const char *intermed(void); -static struct obj *find_qarti(struct obj *); +/* sometimes find_qarti(gi.invent), and gi.invent can be null */ +static struct obj *find_qarti(struct obj *) NO_NONNULLS; static const char *neminame(void); static const char *guardname(void); static const char *homebase(void); diff --git a/src/save.c b/src/save.c index 460601206..74bbb757a 100644 --- a/src/save.c +++ b/src/save.c @@ -23,10 +23,10 @@ static void save_bubbles(NHFILE *, xint8); static void save_stairs(NHFILE *); static void save_bc(NHFILE *); static void saveobj(NHFILE *, struct obj *); -static void saveobjchn(NHFILE *, struct obj **); +static void saveobjchn(NHFILE *, struct obj **) NO_NONNULLS; static void savemon(NHFILE *, struct monst *); -static void savemonchn(NHFILE *, struct monst *); -static void savetrapchn(NHFILE *, struct trap *); +static void savemonchn(NHFILE *, struct monst *) NO_NONNULLS; +static void savetrapchn(NHFILE *, struct trap *) NO_NONNULLS; static void save_gamelog(NHFILE *); static void savegamestate(NHFILE *); static void savelev_core(NHFILE *, xint8); diff --git a/src/zap.c b/src/zap.c index 614ed9940..1ed645ccd 100644 --- a/src/zap.c +++ b/src/zap.c @@ -13,7 +13,7 @@ #define MAGIC_COOKIE 1000 static int zaptype(int); -static void probe_objchain(struct obj *); +static void probe_objchain(struct obj *) NO_NONNULLS; static boolean zombie_can_dig(coordxy x, coordxy y); static void polyuse(struct obj *, int, int); static void create_polymon(struct obj *, int);