{"id":3227,"date":"2013-02-12T12:02:17","date_gmt":"2013-02-12T02:02:17","guid":{"rendered":"http:\/\/www.flamingspork.com\/blog\/?p=3227"},"modified":"2013-02-12T12:02:17","modified_gmt":"2013-02-12T02:02:17","slug":"fun-with-coverity-found-bugs-episode-1","status":"publish","type":"post","link":"https:\/\/www.flamingspork.com\/blog\/2013\/02\/12\/fun-with-coverity-found-bugs-episode-1\/","title":{"rendered":"Fun with Coverity found bugs (Episode 1)"},"content":{"rendered":"<p>Taking the inspiration of\u00c2\u00a0<a id=\"___hovercard_0\" href=\"https:\/\/plus.google.com\/115100143589352485714\" rel=\"author\" data-gapiscan=\"true\" data-onload=\"true\" data-gapiattached=\"true\">Valeriy Kravchuk<\/a>\u00c2\u00a0great series of <a href=\"http:\/\/mysqlentomologist.blogspot.nl\/\">blog posts &#8220;Fun with Bugs&#8221;<\/a> (and not\u00c2\u00a0<a href=\"http:\/\/funwithbugs.com\/\">http:\/\/funwithbugs.com\/<\/a>\u00c2\u00a0which is about both caring for and eating bugs), and since I recently went and run <a href=\"http:\/\/www.coverity.com\">Coverity<\/a> against <a href=\"http:\/\/www.drizzle.org\">Drizzle<\/a>, I thought I&#8217;d have a small series of posts on bugs that it has found (and I&#8217;ve fixed).<\/p>\n<p>An idea that has been pervasive in the Drizzle project (and one that I rather subscribe to) is that there is two types of correct: correct and obviously correct. Being obviously correct is much, <strong>much<\/strong> better than merely being correct.<\/p>\n<p>The first category of problems that Coverity found was kind of interesting, there was a warning that data_file_name and index_file_name in class ha_myisam weren&#8217;t initialized in the ha_myisam constructor nor in any function that it calls. It turns out that this was basically because the code wasn&#8217;t exactly optimal, and these variables were used kind of oddly. In fact, in writing this blog post I went back and found that there&#8217;s a bunch of extra dead code and these should just be removed, along with the code that &#8220;used&#8221; them.<\/p>\n<p>The historical use for data_file_name and index_file_name were that (in MySQL) you could specify different paths for MyISAM data and index files, so that the FRM ended up in the server datadir, the data file ended up some other place and the index file was off behind the sofa. Since MyISAM is used only for temporary tables in Drizzle, this is entirely not needed.<\/p>\n<p>Another place where a similar bug was found by Coverity was in the SQLExecutor class of the json_server plugin. The _err variable wasn&#8217;t initialized in the constructor. After some careful auditing, I think this was actually a false positive as it was set to something before being used, but it was pretty simple to prevent future bugs by initializing it.<\/p>\n<p>Two instances of the same warning, one just found a bunch of code to delete (rather useful) and the other is rather minor but may help someone in the future.<\/p>\n<p>Coming up next: total embarrassment bugs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Taking the inspiration of\u00c2\u00a0Valeriy Kravchuk\u00c2\u00a0great series of blog posts &#8220;Fun with Bugs&#8221; (and not\u00c2\u00a0http:\/\/funwithbugs.com\/\u00c2\u00a0which is about both caring for and eating bugs), and since I recently went and run Coverity against Drizzle, I thought I&#8217;d have a small series of &hellip; <a href=\"https:\/\/www.flamingspork.com\/blog\/2013\/02\/12\/fun-with-coverity-found-bugs-episode-1\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[76,75],"tags":[633,503,70],"class_list":["post-3227","post","type-post","status-publish","format-standard","hentry","category-code","category-drizzle-work-et-al","tag-code","tag-coverity","tag-drizzle"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5a6n8-Q3","jetpack-related-posts":[{"id":1326,"url":"https:\/\/www.flamingspork.com\/blog\/2008\/12\/23\/drizzle-progress-testing-can-be-good\/","url_meta":{"origin":3227,"position":0},"title":"Drizzle progress&#8230; (testing can be good)","author":"Stewart Smith","date":"2008-12-23","format":false,"excerpt":"We've been working on fixing up the remaining test cases so that they run with Drizzle. We've found: bugs in Drizzle, bugs in MySQL (one that seems to have been there for at least 10 years), bugs in the tests, tests that no longer apply and occationally, something like this:\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2168,"url":"https:\/\/www.flamingspork.com\/blog\/2010\/10\/25\/storage-engine-api-state-graph\/","url_meta":{"origin":3227,"position":1},"title":"Storage Engine API state graph","author":"Stewart Smith","date":"2010-10-25","format":false,"excerpt":"Drizzle still has a number of quirks inherited from the MySQL Storage Engine API (e.g. BLOBs, row buffer, CREATE SELECT and lack of DDL transaction boundaries, key tuple format). One of the things we fixed a long time ago was to have proper methods for StorageEngines to be called for:\u2026","rel":"","context":"In &quot;code&quot;","block_context":{"text":"code","link":"https:\/\/www.flamingspork.com\/blog\/category\/code\/"},"img":{"alt_text":"State transitions for a transaction. Transaction can be empty OR have one or more statements","src":"https:\/\/i0.wp.com\/www.flamingspork.com\/blog\/wp-content\/uploads\/2010\/10\/edge30-300x163.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2323,"url":"https:\/\/www.flamingspork.com\/blog\/2011\/03\/17\/things-ive-done-in-drizzle\/","url_meta":{"origin":3227,"position":2},"title":"Things I&#8217;ve done in Drizzle","author":"Stewart Smith","date":"2011-03-17","format":false,"excerpt":"When writing my Dropping ACID: Eating Data in a Web 2.0 Cloud World talk for LCA2011 I came to the realisation that I had forgotten a lot of the things I had worked on in MySQL and MySQL Cluster. So, as a bit of a retrospective as part of the\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2041,"url":"https:\/\/www.flamingspork.com\/blog\/2010\/06\/29\/enum-now-works-properly-in-drizzle\/","url_meta":{"origin":3227,"position":3},"title":"ENUM now works properly (in Drizzle)","author":"Stewart Smith","date":"2010-06-29","format":false,"excerpt":"Over at the Drizzle blog, the recent 2010-06-07 tarball was announced. This tarball release has my fixes for the ENUM type, so that it now works as it should. I was quite amazed that such a small block of code could have so many bugs! One of the most interesting\u2026","rel":"","context":"In &quot;drizzle&quot;","block_context":{"text":"drizzle","link":"https:\/\/www.flamingspork.com\/blog\/category\/work-et-al\/drizzle-work-et-al\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1405,"url":"https:\/\/www.flamingspork.com\/blog\/2009\/02\/18\/fun-with-387\/","url_meta":{"origin":3227,"position":4},"title":"Fun with the 387","author":"Stewart Smith","date":"2009-02-18","format":false,"excerpt":"Filed\u00c2\u00a0 GCC bug 39228: #include <stdio.h> #include <math.h> int main() { \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 double a= 10.0; \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 double b= 1e+308; \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 printf(\"%d %d %dn\", isinf(a*b), __builtin_isinf(a*b), __isinf(a*b)); \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 return 0; } mtaylor@drizzle-dev:~$ gcc -o test test.c mtaylor@drizzle-dev:~$ .\/test 0 0 1 mtaylor@drizzle-dev:~$ gcc -o test test.c -std=c99 mtaylor@drizzle-dev:~$ .\/test 1 0\u2026","rel":"","context":"In &quot;code&quot;","block_context":{"text":"code","link":"https:\/\/www.flamingspork.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2161,"url":"https:\/\/www.flamingspork.com\/blog\/2010\/10\/21\/haildb-being-built-by-default-in-drizzle\/","url_meta":{"origin":3227,"position":5},"title":"HailDB being built by default in Drizzle","author":"Stewart Smith","date":"2010-10-21","format":false,"excerpt":"It just it trunk - if you have HailDB installed when you build Drizzle, you will now get the HailDB plugin built. You can even run Drizzle with it (remove innobase plugin, load HailDB plugin). Previously, we had problems building both due to symbol conflicts between innobase and HailDB. We've\u2026","rel":"","context":"In &quot;code&quot;","block_context":{"text":"code","link":"https:\/\/www.flamingspork.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts\/3227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/comments?post=3227"}],"version-history":[{"count":2,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts\/3227\/revisions"}],"predecessor-version":[{"id":3229,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/posts\/3227\/revisions\/3229"}],"wp:attachment":[{"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/media?parent=3227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/categories?post=3227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flamingspork.com\/blog\/wp-json\/wp\/v2\/tags?post=3227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}