|
Message-ID: <CAGw6cBuZJexDb-E+OFXk0ZfJMs4xuLC4cThR1zGjnaQa74z2Og@mail.gmail.com> Date: Tue, 19 Feb 2019 13:09:21 -0800 From: Michael Forney <mforney@...rney.org> To: musl@...ts.openwall.com Subject: Re: Error in getaddrinfo()? On 2019-02-19, Markus Wichmann <nullplan@....net> wrote: > And while we're on the subject, a few lines later we get > > .ai_next = &out[k+1].ai }; > > Now, for the last k, isn't this calculation undefined? The array index > is out of bounds, then. It won't matter what is calculated here, since > the last .ai_next is explicitly nulled a few lines further down, but the > calculation might invoke undefined behavior, and these last few years > compilers have gotten really agressive about that. I don't think it is undefined behavior, as long as it is not dereferenced. See http://port70.net/~nsz/c/c11/n1570.html#6.5.6p8: "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. If the result points one past the last element of the array object, it shall not be used as the operand of a unary * operator that is evaluated."
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.