{"id":21,"date":"2017-12-15T14:40:36","date_gmt":"2017-12-15T12:40:36","guid":{"rendered":"https:\/\/ahiru.eu\/blog\/?p=21"},"modified":"2019-08-07T22:30:29","modified_gmt":"2019-08-07T19:30:29","slug":"bug-of-the-day-2016-12-22","status":"publish","type":"post","link":"https:\/\/ahiru.eu\/blog\/2017\/12\/15\/bug-of-the-day-2016-12-22\/","title":{"rendered":"Bug of the day: 2016-12-22"},"content":{"rendered":"<p>Somewhere, I was receiving an integer and I had to return a filename based on it, where the integer was the sequence number, e.g. 0, 1, 2, etc. I needed to use that integer in a callback, so I was passing it as user_data with a GUINT_TO_POINTER (type casting with some sanity checks) and getting it back with GPOINTER_TO_UINT on the other side. The first file was being written normally, but the second failed. I tried inspecting why and saw this line in the callback:<\/p>\n<pre>MyElement *self = MY_ELEMENT (user_data);<\/pre>\n<p>where &#8220;self&#8221; wasn&#8217;t needed in that callback, I just added it out of habit, because usually user_data is self. It does have some sanity checks there, so the first time worked because user_data was just 0x0 &#8211; so self is NULL, alright. The second time, self was becoming (MyElement *) 0x1, so the sanity check was failing, and kaboom.<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Somewhere, I was receiving an integer and I had to return a filename based on it, where the integer was[&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-21","post","type-post","status-publish","format-standard","hentry","category-bug-of-the-day","category-english"],"_links":{"self":[{"href":"https:\/\/ahiru.eu\/blog\/wp-json\/wp\/v2\/posts\/21","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ahiru.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ahiru.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ahiru.eu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ahiru.eu\/blog\/wp-json\/wp\/v2\/comments?post=21"}],"version-history":[{"count":3,"href":"https:\/\/ahiru.eu\/blog\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":67,"href":"https:\/\/ahiru.eu\/blog\/wp-json\/wp\/v2\/posts\/21\/revisions\/67"}],"wp:attachment":[{"href":"https:\/\/ahiru.eu\/blog\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ahiru.eu\/blog\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ahiru.eu\/blog\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}