From 624eeeb58c6509799333d03fb0afc3ef11282c46 Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 27 Dec 2023 18:15:37 -0800 Subject: [PATCH] non-Null handling for alloc.c I wasn't very systematic but I think I eventually got everything. Most alloc.c declarations are in global.h rather than extern.h. --- include/extern.h | 12 ++++++------ include/global.h | 24 ++++++++++-------------- src/alloc.c | 6 +++--- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/include/extern.h b/include/extern.h index 5421ab33f..e8c7e199b 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.7 extern.h $NHDT-Date: 1703070179 2023/12/20 11:02:59 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1344 $ */ +/* NetHack 3.7 extern.h $NHDT-Date: 1703716146 2023/12/27 22:29:06 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1356 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ @@ -70,14 +70,14 @@ #if 0 /* routines in alloc.c depend on MONITOR_HEAP and are declared in global.h */ -extern long *alloc(unsigned int); +extern long *alloc(unsigned int) NONNULL; #endif extern char *fmt_ptr(const void *) NONNULL; /* moved from hacklib.c to alloc.c so that utility programs have access */ #define FITSint(x) FITSint_(x, __func__, __LINE__) -extern int FITSint_(long long, const char *, int); +extern int FITSint_(long long, const char *, int) NONNULLARG2; #define FITSuint(x) FITSuint_(x, __func__, __LINE__) -extern unsigned FITSuint_(unsigned long long, const char *, int); +extern unsigned FITSuint_(unsigned long long, const char *, int) NONNULLARG2; /* This next pre-processor directive covers almost the entire file, * interrupted only occasionally to pick up specific functions as needed. */ @@ -1404,7 +1404,7 @@ extern boolean is_home_elemental(struct permonst *) NONNULLARG1; extern struct monst *clone_mon(struct monst *, coordxy, coordxy) NONNULLARG1; extern int monhp_per_lvl(struct monst *) NONNULLARG1; extern void newmonhp(struct monst *, int) NONNULLARG1; -extern struct mextra *newmextra(void); +extern struct mextra *newmextra(void) NONNULL; extern struct monst *makemon(struct permonst *, coordxy, coordxy, mmflags_nht); extern struct monst *unmakemon(struct monst *, mmflags_nht) NONNULLARG1; extern boolean create_critters(int, struct permonst *, boolean); @@ -1561,7 +1561,7 @@ extern void restore_waterlevel(NHFILE *) NONNULLARG1; /* ### mkobj.c ### */ -extern struct oextra *newoextra(void); +extern struct oextra *newoextra(void) NONNULL; extern void copy_oextra(struct obj *, struct obj *); extern void dealloc_oextra(struct obj *) NONNULLARG1; extern void newomonst(struct obj *) NONNULLARG1; diff --git a/include/global.h b/include/global.h index be484bcfb..529a1c99d 100644 --- a/include/global.h +++ b/include/global.h @@ -1,4 +1,4 @@ -/* NetHack 3.7 global.h $NHDT-Date: 1657918090 2022/07/15 20:48:10 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.144 $ */ +/* NetHack 3.7 global.h $NHDT-Date: 1703716158 2023/12/27 22:29:18 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.157 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Michael Allison, 2006. */ /* NetHack may be freely redistributed. See license for details. */ @@ -319,9 +319,10 @@ typedef uchar nhsym; if nethack is built with MONITOR_HEAP enabled and they aren't; this declaration has been moved out of the '#else' below to avoid getting a complaint from -Wmissing-prototypes when building with MONITOR_HEAP */ -extern char *dupstr(const char *) NONNULL; -/* same, but return strlen(string) */ -extern char *dupstr_n(const char *string, unsigned int *lenout) NONNULL; +extern char *dupstr(const char *) NONNULL NONNULLARG1; +/* same, but return strlen(string) in extra argument */ +extern char *dupstr_n(const char *string, + unsigned *lenout) NONNULL NONNULLPTRS; /* * MONITOR_HEAP is conditionally used for primitive memory leak debugging. @@ -333,20 +334,15 @@ extern char *dupstr_n(const char *string, unsigned int *lenout) NONNULL; */ #ifdef MONITOR_HEAP /* plain alloc() is not declared except in alloc.c */ -extern long *nhalloc(unsigned int, const char *, int) NONNULL; -extern long *nhrealloc(long *, unsigned int, const char *, int) NONNULL; -extern void nhfree(genericptr_t, const char *, int); -extern char *nhdupstr(const char *, const char *, int) NONNULL; +extern long *nhalloc(unsigned int, const char *, int) NONNULL NONNULLARG2; +extern long *nhrealloc(long *, unsigned int, const char *, + int) NONNULL NONNULLARG3; +extern void nhfree(genericptr_t, const char *, int) NONNULLARG2; +extern char *nhdupstr(const char *, const char *, int) NONNULL NONNULLPTRS; /* this predates C99's __func__; that is trickier to use conditionally because it is not implemented as a preprocessor macro; MONITOR_HEAP wouldn't gain much benefit from it anyway so continue to live without it; if func's caller were accessible, that would be a very different issue */ -#ifndef __FILE__ -#define __FILE__ "" -#endif -#ifndef __LINE__ -#define __LINE__ 0 -#endif #define alloc(a) nhalloc(a, __FILE__, (int) __LINE__) #define re_alloc(a,n) nhrealloc(a, n, __FILE__, (int) __LINE__) #define free(a) nhfree(a, __FILE__, (int) __LINE__) diff --git a/src/alloc.c b/src/alloc.c index 793908bbe..14cd68893 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 alloc.c $NHDT-Date: 1687343500 2023/06/21 10:31:40 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.31 $ */ +/* NetHack 3.7 alloc.c $NHDT-Date: 1703716159 2023/12/27 22:29:19 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.32 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -15,9 +15,9 @@ #endif /*#define FITSint(x) FITSint_(x, __func__, (int) __LINE__)*/ -extern int FITSint_(LUA_INTEGER, const char *, int); +extern int FITSint_(LUA_INTEGER, const char *, int) NONNULLARG2; /*#define FITSuint(x) FITSuint_(x, __func__, (int) __LINE__)*/ -extern unsigned FITSuint_(unsigned long long, const char *, int); +extern unsigned FITSuint_(unsigned long long, const char *, int) NONNULLARG2; char *fmt_ptr(const genericptr) NONNULL;