On Thu, May 06, 2021 at 01:50:48AM +0200, Hiltjo Posthuma wrote:
> I think if the condition is reversed then it is fine:
>
> > - while(isspace(*e) && e > s)
>
> to:
>
> > - while(e > s && isspace(*e))
While it is true reversing the condition solves a single-byte read at
one before s, there is a second instance of UB.
Having a pointer to one before an object is in of itself UB in C, it's
on the side of language lawyering, but it's UB.
I add here a quote from a C standard draft:
> When an expression that has integer type is added to or subtracted
> from a pointer, the result has the type of the pointer operand.
> If both the pointer operand and the result point to elements of the
> same array object, or one past the last element of the array object,
> the evaluation shall not produce an overflow; otherwise, the
> behavior is undefined.
Taken from:
http://www.iso-9899.info/n1570.html#6.5.6p8
Received on Thu May 06 2021 - 02:28:13 CEST