Re: MISRA


Abramo Bagnara
 

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

Il 19/12/21 23:36, Nicolas Pitre ha scritto:
all compilers capable of compiling Zephyr I have access to do produce
the right result, *all* the time. It is true whether or not the pointer
being NULL is known at compile time (when it is the compiler also does
constant propagation optimizations on it). It is not because something
is "undefined" that it is necessarily "forbidden".
No, it is not forbidden, it is in the domain "you can do what you want, but be
prepared to pay the price" and the price is unspecified.
For the n-th time I'll repeat this: it can be tested.
In this particular case it is extensively tested by the CI
infrastructure. In the unlikely event one compiler implementation
decides to exercise its freedom to change the existing behavior then
we'll know about it right away.
But you keep on dismissing this fact.
No, I simply keep stating the obvious: you can test a finite number of instances but not all of them and a compiler is free to bite you where you don't expect that (just like you are free to infringe any contract with your compiler).

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.

As the technical arguments seems to not have effects, please imagine to sell the following as a safe state-of-the-art piece of software:

abramo@igor:/tmp$ cat z.c
#include <stddef.h>

int main() {
int *x = NULL;
int *y = x + 4;
return y - x;
}

abramo@igor:/tmp$ clang z.c -fsanitize=undefined
abramo@igor:/tmp$ ./a.out
z.c:5:14: runtime error: applying non-zero offset 16 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior z.c:5:14 in

I confess that I would be embarassed by that, but I'm sure many person are better seller than me ;-)

--
Abramo Bagnara

BUGSENG srl - http://bugseng.com
mailto:abramo.bagnara@bugseng.com

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