Russ Cox wrote:
> The test for wraparound when computing len in sprint looks like:
>         len = 1<<30;  /* big number, but sprint is deprecated anyway */
>         /*
>          * on PowerPC, the stack is near the top of memory, so
>          * we must be sure not to overflow a 32-bit pointer.
>          */
>         if(buf+len < buf)
>                 len = -(uintptr)buf-1;

There are several serious portability issues with that.
The main thing is that casting a pointer to an integer type
does not in general produce a "byte address", but rather
just some encoding that can be converted back to a pointer.

And of course buf+len produces undefined behavior if buf
does not point to an array of length at least len.

Such an address-range check chould be delegated to an
auxiliary function that is tailored to the platform as
part of the porting process.  That way whatever nonportable
kludge is used won't silently find its way into a port
where it doesn't work.

Reply via email to