<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Sep 2, 2014 at 10:44 AM, Hans Wennborg <span dir="ltr"><<a href="mailto:hans@chromium.org" target="_blank">hans@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":cqt" class="a3s" style="overflow:hidden">I'm attaching a patch that should make this UB-proof. Let me know what<br>
you think.<br></div></blockquote></div><br>The reason I didn't suggest this originally is that it doesn't actually make anything UB-proof. You're still potentially walking a pointer far past the end of the allocated array and comparing it with a pointer one past the end of the array. You need to check every single time prior to adding that there is space within the allocated array.</div><div class="gmail_extra"><br></div><div class="gmail_extra">As an example of how I think this could fail, imagine that your system maps pointers to uintptr_t such that 'End' becomes std::numeric_limits<uintptr_t>::max() and either the aligning or the size addition wrap.</div><div class="gmail_extra"><br></div><div class="gmail_extra">If you want to go this route, at least use intptr_t so we get a UBSan failure if this state ever arises. Better would be to just reformulate the entire thing in terms that are guaranteed to only use pointers within the allocated array.</div></div>