eliminate static analysis complaints about eat.c
This is fairly ridiculous but it prevents the bogus complaints when compiling eat.c with 'gcc -fanalyzer' about some fields in gc.context.victual being used without having been initialized. There's bound to be a better way to handle this and I'm curious whether it will work with the 'onefile' testing.
This commit is contained in:
@@ -332,6 +332,7 @@ extern void destroy_drawbridge(coordxy, coordxy);
|
|||||||
/* ### decl.c ### */
|
/* ### decl.c ### */
|
||||||
|
|
||||||
extern void decl_globals_init(void);
|
extern void decl_globals_init(void);
|
||||||
|
extern void sa_victual(volatile struct victual_info *);
|
||||||
|
|
||||||
/* ### detect.c ### */
|
/* ### detect.c ### */
|
||||||
|
|
||||||
|
|||||||
+13
@@ -1048,4 +1048,17 @@ decl_globals_init(void)
|
|||||||
long verbosity_suppressions[vb_elements] = { 0L, 0L, 0L, 0L, 0L, };
|
long verbosity_suppressions[vb_elements] = { 0L, 0L, 0L, 0L, 0L, };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* gcc 12.2's static analyzer thinks that some fields of gc.context.victual
|
||||||
|
are uninitialized when compiling 'bite(eat.c)' but that's impossible;
|
||||||
|
it is defined at global scope so guaranteed to be given implicit
|
||||||
|
initialization for fields that aren't explicitly initialized (all of
|
||||||
|
'context'); having bite() pass &gc.context.victual to this no-op
|
||||||
|
eliminates the analyzer's very verbose complaint */
|
||||||
|
void
|
||||||
|
sa_victual(
|
||||||
|
volatile struct victual_info *context_victual UNUSED)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*decl.c*/
|
/*decl.c*/
|
||||||
|
|||||||
@@ -2983,6 +2983,9 @@ use_tin_opener(struct obj *obj)
|
|||||||
static int
|
static int
|
||||||
bite(void)
|
bite(void)
|
||||||
{
|
{
|
||||||
|
/* hack to pacify static analyzer incorporated into gcc 12.2 */
|
||||||
|
sa_victual(&gc.context.victual);
|
||||||
|
|
||||||
if (gc.context.victual.canchoke && u.uhunger >= 2000) {
|
if (gc.context.victual.canchoke && u.uhunger >= 2000) {
|
||||||
choke(gc.context.victual.piece);
|
choke(gc.context.victual.piece);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user