pacify static analyzer - vision.c

Include some assertions to convince the analyzer that some pointers
can't be Null.  They're Null if 'vis_func' is non-Null but only used
when that function pointer is Null and they have values.

If there's a macro that's defined when the analyzer is running and
undefined when not--or vice versa--it could be used to control NDEBUG
and avoid the assertion code when not analyzing.  That's a bit like
using fake code to pacify 'lint'; however, since the assertions should
never fail, suppressing them isn't really switching to fake code.

I reordered a couple of macros so that the set of them matches the
comment which precedes them and refers to "the last three".  It is
referring to the three within the block comment rather than the macro
defintions but putting those in the same order removes any ambiguity.
This commit is contained in:
PatR
2023-01-18 11:57:49 -08:00
parent 4571a49b3f
commit f61cfe7e48

View File

@@ -3,6 +3,7 @@
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
#include <assert.h>
/* Circles
* ==================================================================*/
@@ -1129,16 +1130,29 @@ static genericptr_t varg;
*
* The last three macros depend on having local pointers row_min, row_max,
* and rowp being set correctly.
*
* The assertions are included to pacify a static source code analyzer.
* Compile with NDEBUG defined to suppress them.
*/
#define set_cs(rowp, col) (rowp[col] = COULD_SEE)
#define good_row(z) ((z) >= 0 && (z) < ROWNO)
#define set_min(z) \
if (*row_min > (z)) \
*row_min = (z)
#define set_max(z) \
if (*row_max < (z)) \
*row_max = (z)
#define is_clear(row, col) viz_clear_rows[row][col]
#define good_row(z) ((z) >= 0 && (z) < ROWNO)
#define set_cs(rowp, col) \
do { \
assert(rowp != NULL); \
rowp[col] = COULD_SEE; \
} while (0)
#define set_min(z) \
do { \
assert(row_min != NULL); \
if (*row_min > (z)) \
*row_min = (z); \
} while (0)
#define set_max(z) \
do { \
assert(row_max != NULL); \
if (*row_max < (z)) \
*row_max = (z); \
} while (0)
/*
* clear_path() expanded into 4 macros/functions: