fix static analyzer vs alloc.c
gcc-13.1 static analyzer complains that alloc() returns long * without guaranteeing to allocate an integral number of longs. Fix by rounding the requested amount up to the next long when dividing the amount by 'sizeof (long)' yields a remainder. Surprisingly--to me, at least--the analyzer recognizes that this extra argument manipulation will always produce a viable amount no matter what alloc()'s caller passes in. Also, the declarations for alloc() and re_alloc() in alloc.c didn't match the ones in global.h for the MONITOR_HEAP config. I guess nobody has tested that since NONNULL got introduced. A year ago the two FITSxxx routines were moved from hacklib.c to alloc.c so that they could easily be linked into various programs instead of being replicated in each, but the declarations for them weren't moved from hacklib.c section in extern.h to alloc.c one.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.7 extern.h $NHDT-Date: 1687036542 2023/06/17 21:15:42 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1275 $ */
|
||||
/* NetHack 3.7 extern.h $NHDT-Date: 1687343496 2023/06/21 10:31:36 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1276 $ */
|
||||
/* Copyright (c) Steve Creps, 1988. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
@@ -8,9 +8,15 @@
|
||||
/* ### alloc.c ### */
|
||||
|
||||
#if 0
|
||||
/* routines in alloc.c depend on MONITOR_HEAP and are declared in global.h */
|
||||
extern long *alloc(unsigned int);
|
||||
#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);
|
||||
#define FITSuint(x) FITSuint_(x, __func__, __LINE__)
|
||||
extern unsigned FITSuint_(unsigned long long, const char *, int);
|
||||
|
||||
/* This next pre-processor directive covers almost the entire file,
|
||||
* interrupted only occasionally to pick up specific functions as needed. */
|
||||
@@ -1088,10 +1094,6 @@ extern void shuffle_int_array(int *, int);
|
||||
nh_snprintf(__func__, __LINE__, str, size, __VA_ARGS__)
|
||||
extern void nh_snprintf(const char *func, int line, char *str, size_t size,
|
||||
const char *fmt, ...) PRINTF_F(5, 6);
|
||||
#define FITSint(x) FITSint_(x, __func__, __LINE__)
|
||||
extern int FITSint_(long long, const char *, int);
|
||||
#define FITSuint(x) FITSuint_(x, __func__, __LINE__)
|
||||
extern unsigned FITSuint_(unsigned long long, const char *, int);
|
||||
#ifdef ENHANCED_SYMBOLS
|
||||
extern int unicodeval_to_utf8str(int, uint8 *, size_t);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user