problems with "clobbered" warnings

Zack Weinberg
Thu Jun 22 15:12:00 GMT 2000

On Thu, Jun 22, 2000 at 05:19:00PM -0400, Michael Richardson wrote:
>   I am attempting to get some code to compile with -Wall -Werror. I have just
> introduced a setjmp() to catch errors...
>   I get warnings like:
> paxas.c:211: warning: variable `infilename' might be clobbered by `longjmp' or `vfork'
>   Is there someone who can offer a better description of when a variable may
> be considered to be clobbered, or a workaround that permits me to shut up
> just that test without giving up on the uninitialized warning?

The compiler generates those warnings for just about every variable in
a function that calls setjmp or vfork.

Your best option is not to use setjmp() at all.  Have a
cleanup_and_exit() that cleans up and calls exit; mark it noreturn;
and call it directly whenever you would have called longjmp.

If that's not feasible for some reason, you may be able to structure
your code like this:

jmp_buf env;

      return 1;

  return 0;

- the key being to have no actual code in the routine that calls
setjmp, just function calls.


More information about the Gcc-bugs mailing list