<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 22, 2016, at 4:14 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Tue, Mar 22, 2016 at 3:59 PM, Pete Cooper via llvm-commits<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Author: pete<br class="">Date: Tue Mar 22 17:59:35 2016<br class="">New Revision: 264115<br class=""><br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=264115&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=264115&view=rev</a><br class="">Log:<br class="">Avoid memcpy from nullptr.  NFC.<br class=""><br class="">This was caught by the UBSan bot.  When the atom has no size, we would<br class="">issue a memcpy with size0 and a nullptr for the source.<br class=""><br class="">Also, this code should never have references inside an empty atom so<br class="">add an assert for that while we're here.<br class=""><br class="">Modified:<br class="">   <span class="Apple-converted-space"> </span>lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp<br class=""><br class="">Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp?rev=264115&r1=264114&r2=264115&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp?rev=264115&r1=264114&r2=264115&view=diff</a><br class="">==============================================================================<br class="">--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp (original)<br class="">+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp Tue Mar 22 17:59:35 2016<br class="">@@ -420,6 +420,11 @@ void ArchHandler_x86::generateAtomConten<br class="">                                           FindAddressForAtom findSectionAddress,<br class="">                                           uint64_t imageBaseAddress,<br class="">                                           uint8_t *atomContentBuffer) {<br class="">+  if (!atom.size()) {<br class="">+    assert(atom.begin() == atom.end() &&<br class="">+           "Cannot have references without content");<br class=""></blockquote><div class=""><br class=""></div><div class="">Um, that seems like a problematic API, if size can be distinct from end() - begin() ? Perhaps some of these should be renamed to avoid confusion?</div></div></div></blockquote>Yeah…</div><div><br class=""></div><div>Its not very standard.  begin and end walk the Reference’s, but size() is about the number of bytes of content in the atom.  The two are completely unrelated.</div><div><br class=""></div><div>We should probably make size count the references, or remove size entirely, and have a contentSize() method where we have size() now.</div><div><br class=""></div><div>Thanks for pointing this out. I became somewhat used to it, but its actually quite non-intuitive so i should really fix it.</div><div><br class=""></div><div>Cheers,</div><div>Pete</div><div><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">+    return;<br class="">+  }<br class="">   // Copy raw bytes.<br class="">   memcpy(atomContentBuffer, atom.rawContent().data(), atom.size());<br class="">   // Apply fix-ups.<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a></blockquote></div></div></blockquote></div><br class=""></body></html>