Avoid undefined behaviour in m68hc11 md_begin

Alan Modra amodra@gmail.com
Tue Mar 28 12:18:34 GMT 2023


On Tue, Mar 28, 2023 at 01:19:38PM +0200, Andreas Schwab wrote:
> On Mär 28 2023, Alan Modra via Binutils wrote:
> 
> > Given p = A where p is a pointer to some type and A is an array of
> > that type, then the expression p - 1 + 1 evokes undefined behaviour
> > according to the C standard.
> >
> > gcc-13 -fsanitize=address,undefined complains about this, but not
> > where the undefined behaviour actually occurs at tc-m68hc11.c:646.
> > Instead you get an error: "tc-m68hc11.c:708:20: runtime error: store
> > to address 0x62600000016c with insufficient space for an object of
> > type 'int'".  Which is a lie.
> 
> It's not a lie if you regard p-1 as no longer being associated with A,
> so that p-1+1 cannot move back into it any more.

The error message specifies an address.  That address is part of the
memory allocated.  To say there is insufficient space at that address
is indeed a lie.

Please note that I'm not saying anyone should spend time fixing this
diagnostic.  I truly don't care.  After all, it was good enough to
find the undefined behaviour in a relatively short time.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list