seccomp / libseccomp

The main libseccomp repository
GNU Lesser General Public License v2.1
791 stars 170 forks source link

BUG: gcc warning in gen_bpf.c #422

Open drakenclimber opened 9 months ago

drakenclimber commented 9 months ago
gen_bpf.c: In function '_gen_bpf_build_bpf':
gen_bpf.c:2077:21: warning: storing the address of local variable 'pseudo_arch' in '*state.arch' [-Wdangling-pointer=]
 2077 |         state->arch = &pseudo_arch;
      |         ~~~~~~~~~~~~^~~~~~~~~~~~~~
gen_bpf.c:1999:25: note: 'pseudo_arch' declared here
 1999 |         struct arch_def pseudo_arch;
      |                         ^~~~~~~~~~~
gen_bpf.c:1985:49: note: 'state' declared here
 1985 | static int _gen_bpf_build_bpf(struct bpf_state *state,
      |                               ~~~~~~~~~~~~~~~~~~^~~~~
drakenclimber commented 9 months ago

GCC complains about storing a pointer to a local stack variable in a struct that is used outside of _gen_bpf_build_bpf(). While the state struct is used after _gen_bpf_build_bpf() returns, the state->arch variable is not.

So we should clean this up, but it's not currently being used improperly.

xen0n commented 2 weeks ago

Triage: this seems already fixed by commit 31583fab12370da984785cd16ceb8f031c94ae76.

pcmoore commented 22 hours ago

FWIW, I'm not seeing this either with HEAD at 2847f10dddca72167309c04cd09f326fd3b78e2f and GCC v14.2.1, @drakenclimber are you still seeing this warning?