{"id":23,"date":"2007-08-29T14:32:07","date_gmt":"2007-08-29T20:32:07","guid":{"rendered":"http:\/\/blog.blockos.org\/?p=71"},"modified":"2007-08-29T14:32:07","modified_gmt":"2007-08-29T20:32:07","slug":"zero-right-ahead","status":"publish","type":"post","link":"https:\/\/blog.blockos.org\/?p=23","title":{"rendered":"Zero right ahead!"},"content":{"rendered":"<p>Yes! Zero wouldn&#8217;t be considered as the default\/standard return error value. I learnt the hard way today.<\/p>\n<p>I had some kind of weird NULL pointer bug. After some investigations, i found that the deserialization function was failing at some point leaving the whole structure uninitialized. First i blamed myself for not calling the standard structure initialization function when the deserialization function failed. Then i looked at the data file.<br \/>\nEverything seemed to be ok. So i went on a step by step execution with the debugger. 5 minutes later i found the culprit. It was <a href=\"http:\/\/www.zlib.net\/\">zlib<\/a>  in the kitchen with ten tone hammer. It was strange.<\/p>\n<p>Let&#8217;s say that i compressed a buffer of N bytes into M bytes. When i read back the N bytes from the compressed buffer, i get the whole data before the end of the compressed buffer. Leaving me with 5 extra bytes.<br \/>\nOn the next run i try to read P bytes. But i still have those 5 bytes to decompress. So i feed them to <a href=\"http:\/\/zlib.net\/manual.html#inflate\">inflate<\/a> (the zlib decompression routine). It returns a nice <a href=\"http:\/\/zlib.net\/manual.html#Z_STREAM_END\">Z_STREAM_END<\/a>. At this point, nothing wrong as i finished to process the previous compressed buffer. But (and that&#8217;s a big but &nbsp;&nbsp;&nbsp; &#8230; &nbsp;&nbsp;&nbsp; sorry &nbsp;&nbsp;&nbsp;) no bytes were output.<br \/>\nIn fact it&#8217;s an excellent news as we already get the N bytes back. So this bytes are &#8230; what&#8230; padding bytes ?<br \/>\nAnyway, the fact that i got 0 bytes back without any <a href=\"http:\/\/www.zlib.net\">zlib<\/a> or system error was a relief. But the &#8220;dezip&#8221; function is returning 0 on error or the size of the decompressed data when everything works&#8230;<br \/>\nSo&#8230; I was considering that the &#8220;dezip&#8221; function failed even if everything was alright.<\/p>\n<p>The whole issue was fixed in 5 minutes by changing the default error value from 0 to -1&#8230;.<\/p>\n<p>I spent the whole day tracking this bug&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yes! Zero wouldn&#8217;t be considered as the default\/standard return error value. I learnt the hard way today. I had some kind of weird NULL pointer bug. After some investigations, i found that the deserialization function was failing at some point leaving the whole structure uninitialized. First i blamed myself for\u2026 <a class=\"continue-reading-link\" href=\"https:\/\/blog.blockos.org\/?p=23\">Continue reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[27],"_links":{"self":[{"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/posts\/23"}],"collection":[{"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=23"}],"version-history":[{"count":0,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.blockos.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}