{"id":4848,"date":"2014-03-30T16:06:20","date_gmt":"2014-03-30T16:06:20","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/memcpy-cast-to-pointer-from-integer-of-different-size-collection-of-common-programming-errors\/"},"modified":"2014-03-30T16:06:20","modified_gmt":"2014-03-30T16:06:20","slug":"memcpy-cast-to-pointer-from-integer-of-different-size-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/memcpy-cast-to-pointer-from-integer-of-different-size-collection-of-common-programming-errors\/","title":{"rendered":"memcpy &#8211; cast to pointer from integer of different size-Collection of common programming errors"},"content":{"rendered":"<p>Neither <code>JMP[1]<\/code> nor <code>JMPSize<\/code> are pointers. This means that <code>memcpy<\/code> will interpret the actual values of the variables as pointers, which will then point to somewhere way off and lead to undefined behavior.<\/p>\n<p>You need to use the address-of operator <code>&amp;<\/code> to make them pointers:<\/p>\n<pre><code>memcpy(&amp;JMP[1], &amp;JMPSize, 4);\n<\/code><\/pre>\n<p>Generally, if a functions takes a <code>void *<\/code> argument, or returns <code>void *<\/code>, then <em>don&#8217;t<\/em> cast the types. Not casting the types will give you warnings, and warnings are in many cases indicators of undefined behavior.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Neither JMP[1] nor JMPSize are pointers. This means that memcpy will interpret the actual values of the variables as pointers, which will then point to somewhere way off and lead to undefined behavior. You need to use the address-of operator &amp; to make them pointers: memcpy(&amp;JMP[1], &amp;JMPSize, 4); Generally, if a functions takes a void [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4848","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4848"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4848\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}