alloc() never returns Null

Mark alloc()--also dupstr() and re_alloc()--for gcc and clang as
always returning non-Null.  This should silence some of the static
analysis complaints.

Almost all the monster and object naming functions (anything that
returns an mbuf or an obuf) should be marked this way too but I'll
leave that for somebody else to deal with.

I didn't attempt to mark alloc() with the 'malloc' attribute because
macro definitions could end up causing trouble.  Specifying its
deallocator would probably be useful but is at even bigger risk of
macro interference.

I'm not sure whether gcc 3 is really the right test for whether the
returns_nonnull attribute setting is available.
This commit is contained in:
PatR
2022-09-24 04:39:12 -07:00
parent ef093d0b30
commit 4885653014
4 changed files with 17 additions and 12 deletions

View File

@@ -10,7 +10,7 @@
#if 0
extern long *alloc(unsigned int);
#endif
extern char *fmt_ptr(const void *);
extern char *fmt_ptr(const void *) NONNULL;
/* This next pre-processor directive covers almost the entire file,
* interrupted only occasionally to pick up specific functions as needed. */