<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 2, 2014 at 8:07 PM, Nick Kledzik <span dir="ltr"><<a href="mailto:kledzik@apple.com" target="_blank">kledzik@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":4a8" style="overflow:hidden">On <span class="aBn" tabindex="0"><span class="aQJ">Jan 2, 2014</span></span>, at <span class="aBn" tabindex="0"><span class="aQJ">4:41 PM</span></span>, Joey Gouly <<a href="mailto:joey.gouly@gmail.com">joey.gouly@gmail.com</a>> wrote:\<br>

<div class="im">><br>
><br>
> ================<br>
> Comment at: lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp:282<br>
> @@ -280,1 +281,3 @@<br>
> +        io, sect.content);<br>
> +    io.mapOptional("content",         content->normalizedContent);<br>
>     io.mapOptional("relocations",     sect.relocations);<br>
> ----------------<br>
> <a href="mailto:kledzik@apple.com">kledzik@apple.com</a> wrote:<br>
>> I think you can just cast the address of sect.content to be of type ContentBytes and it should all just work with no need for NormalizedContent.<br>
> mapOptional wants a reference to the content, so I cant use the address of content, and as far as I can tell, I can't change the type of a reference.<br>
><br>
> Unless I'm mistaken, I can't do this without copying.<br>
<br>
</div>This works for me:<br>
<br>
Index: lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp<br>
===================================================================<br>
--- lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp  (revision 198349)<br>
+++ lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp  (working copy)<br>
@@ -276,7 +276,8 @@<br>
     io.mapOptional("attributes",      sect.attributes);<br>
     io.mapOptional("alignment",       sect.alignment, 0U);<br>
     io.mapRequired("address",         sect.address);<br>
-    io.mapOptional("content",         sect.content);<br>
+    ContentBytes &cont = *reinterpret_cast<ContentBytes*>(&sect.content);</div></blockquote></div><br>Using the vector after this is totally undefined behavior. You can't just cast vector<T>* to vector<U>* and then access the vector with that pointer when T != U. It doesn't matter what the layout or size of T and U are, the vector types are completely different and might have nothing to do with each other.</div>
</div>