build: Add -Wclobbered to detect problems with longjmp
When we jump back to a save point in UCI_THROW() with longjmp all the
registers will be reset to the old values when we called UCI_TRAP_SAVE()
last time, but the memory is not restored. This will revert all the
variables which are stored in registers, but not the variables stored on
the stack.
Mark all the variables which the compiler could put into a register as
volatile to store them safely on the stack and make sure they have the
defined current values also after longjmp was called.
The setjmp() manage says the following:
----------------------------------------------------------------------
The compiler may optimize variables into registers, and longjmp()
may restore the values of other registers in addition to the stack
pointer and program counter. Consequently, the values of automatic
variables are unspecified after a call to longjmp() if they meet all the
following criteria:
* they are local to the function that made the corresponding setjmp()
call;
* their values are changed between the calls to setjmp() and longjmp();
and
* they are not declared as volatile.
---------------------------------------------------------------------
The -Wclobbered compiler option warns about all variables which are
written after setjmp() was called, not all of them could cause problems,
but to make sure to catch all real problems add this warning and fix all
occurrences of this warning.
This also activates a compiler warning which should warn us in such
cases.
This could fix some potential problems in error paths like the one
reported in CVE-2019-15513.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>