On Monday, 12 April 2021 at 19:58:11 UTC+1, Richmond wrote:
> Barry Schwarz <
schw...@delq.com> writes:
>
> > Once you cause undefined behavior (by accessing beyond the bounds of
> > your array), there is no expectation of any particular behavior nor is
> > there any expectation of consistency in that behavior. Anything that
> > can happen can happen.
> I thought the address sanitiser was supposed to stop it.
>
"Undefined behaviour" means two things. It means that the C standard imposes
on constraint on what the program does after it executes the instruction. And
it means that such a program is considered to be erroneous. However it doesn't
mean that the program exists in some sort of philoosphical state of indefinition.
This has historically caused some misunderstanding on this newsgroup. Other
factors than the C standard are allowed to impose a behaviour. In fact that is partly
why we say "the behaviour is undefined" rather than "It writes a byte to address one
past the array". A good operating system will say "this means that the program will
exit with an error message". That's the best thing it can do, in the common situation
that no results are better than the wrong results.
Your address sanitiser should give a diagnostic for every illegal array access. If it
doesn't, it's not a very good address sanitiser. It could be bugged, or it could be that
it's hard to make it work in all circumstances with the compiler and OS, and it's
been shipped with known deficiencies.