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.
This commit is contained in:
PatR
2023-12-27 18:15:37 -08:00
parent caf436934e
commit 624eeeb58c
3 changed files with 19 additions and 23 deletions

View File

@@ -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__)