Re: MISRA


Nicolas Pitre <nico@...>
 

On Mon, 20 Dec 2021, Abramo Bagnara wrote:

Il 20/12/21 17:45, Nicolas Pitre ha scritto:
On Mon, 20 Dec 2021, Abramo Bagnara wrote:

Il 20/12/21 15:45, Nicolas Pitre ha scritto:
PS: You should have a look at tests/lib/c_lib/src/main.c. Lots of
"undefined" stuff being tested in there, including not very useful
stuff.
Perhaps you should be more specific pointing to a test that verifies that
something expected happens for a behavior that is undefined for the C
standard
and is not a documented compiler extension.
volatile long long_max = LONG_MAX;
volatile long long_one = 1L;

void test_limits(void)
{
zassert_true((long_max + long_one == LONG_MIN), NULL);
}

It is an undefined behavior per one of your previous examples. But it
passes here because variables are volatile. I still challenge you to
point at some gcc extension documentation mentioning that the use of
volatile makes two's complement wrap the expected behavior.
I confirm that this is ugly (and dangerous) as hell and I really hope that
this is not taken for granted in any part of Zephyr code.
I agree.

Do you really think that the Zephyr comunity wants to play this game, instead
to use unsigned when wrapping is wanted?

What would be the profit doing that?
I don't know why that test and a couple others were created.
This is demonstrably extremely brittle and untrustworthy.


Nicolas

Join devel@lists.zephyrproject.org to automatically receive all group messages.