[PATCH v2 2/2] test: unit test for longjmp
Heinrich Schuchardt
xypron.glpk at gmx.de
Wed Mar 24 12:16:48 CET 2021
On 24.03.21 10:18, Andreas Schwab wrote:
> On Mär 22 2021, Sean Anderson wrote:
>
>> int test_longjmp_ret(int i)
>> {
>> jmp_buf env;
>> int ret;
>> int foo = i;
>>
>> ret = setjmp(env);
>> if (ret)
>> return foo;
>> foo = 0x1000;
>> longjmp(env, i);
>> /* We should not arrive here */
>> return foo;
>
> This is undefined. When modifying a non-volatile auto variable between
> setjmp and longjmp, there is no requirement that the value is preserved.
>
> Andreas.
>
Hello Andreas,
thank you for reviewing.
Your comment relates to the following paragraph in the C99 specification:
"All accessible objects have values, and all other components
of the abstract machine have state, as of the time the longjmp
function was called, except that the values of objects of
automatic storage duration that are local to the function
containing the invocation of the corresponding setjmp macro that
do not have volatile-qualified type and have been changed
between the setjmp invocation and longjmp call are indeterminate."
And foo is obviously "changed between the setjmp invocation and longjmp
call".
The current version of the patch is:
https://patchwork.ozlabs.org/project/uboot/patch/20210323181127.32411-3-xypron.glpk@gmx.de/
So I guess we have to declare env as volatile in setjmp() in this
version of the patch because it is changed between the setjmp and
longjmp invocations?
Best regards
Heinrich
More information about the U-Boot
mailing list