{"id":1135,"date":"2013-03-23T16:59:52","date_gmt":"2013-03-23T06:59:52","guid":{"rendered":"http:\/\/brnz.org\/hbr\/?p=1135"},"modified":"2013-03-26T15:43:19","modified_gmt":"2013-03-26T05:43:19","slug":"bugs-of-the-day-2013-03-21","status":"publish","type":"post","link":"https:\/\/brnz.org\/hbr\/?p=1135","title":{"rendered":"Bugs of the day, Thursday 2013-03-21"},"content":{"rendered":"<h2>Failed to initialize instance-specific member variable correctly because I was calling the wrong constructor<\/h2>\n<pre escaped=\"true\" lang=\"cpp\">struct Foo {\r\n\u00a0 bool m_B;\r\n\u00a0 Foo(Bar&amp; bar) : m_B(true) { \/*do something else with bar*\/ }\r\n};\r\nstruct Baz : public Foo {\r\n\u00a0 Baz(Foo&amp; foo):Foo(foo) {}\r\n};<\/pre>\n<p>Thinking that <strong>Baz::Baz(Foo&amp;)<\/strong> was calling the defined construct-from-reference-to-bar constructor that would initialize <strong>m_B<\/strong> to a particular state when in fact I was calling the compiler-generated copy constructor that would not.<\/p>\n<p>Yet another case of pay attention-to-what-you&#8217;re-doing. The thing that got me this time was that this codebase doesn&#8217;t have a lot of construct-from-reference, so led to the trap of if it compiles, it&#8217;s probably OK.<\/p>\n<p>Quite possibly this was fallout from yesterday&#8217;s the slicing-inheritance bug where I changed inheritance to a pointer-member, but didn&#8217;t change the construction call.<\/p>\n<h2>Use of uninitialized system<\/h2>\n<p>Calling functions in a particular system without having called the appropriate System::Init() function. The results aren&#8217;t pretty.<\/p>\n<p>This was caused by carelessness when un-shelving a partial rework of the init and use of the particular system.<\/p>\n<p>Keeping track of where particular code is being called requires extra effort when managing multiple versions of the same files. Clearly, I&#8217;m too easy to confuse and need to be more careful, and to work with fewer variations.<\/p>\n<p>In general, checks\/asserts in the external interfaces to a system are probably worthwhile to catch this kind of thing a little sooner.<\/p>\n<h2>Yet another uninitialized member variable crash<\/h2>\n<p>In a rework of a rework of a rework of some code I lost a couple of struct member initializers.<\/p>\n<p>Init to zero, all works as expected. Sigh.<\/p>\n<h2>End of day reflection:<\/h2>\n<p>Making changes to a previously-working system, it would have been profitable to spend some time to capture the known-good output (and a record of the known-extant bugs) at the start of the process. I spent some time reverting all my changes and re-building to confirm my analysis of these things, which was not the most efficient approach.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Failed to initialize instance-specific member variable correctly because I was calling the wrong constructor struct Foo { \u00a0 bool m_B; \u00a0 Foo(Bar&amp; bar) : m_B(true) { \/*do something else with bar*\/ } }; struct Baz : public Foo { \u00a0 Baz(Foo&amp; foo):Foo(foo) {} }; Thinking that Baz::Baz(Foo&amp;) was calling the defined construct-from-reference-to-bar constructor that would &hellip; <a href=\"https:\/\/brnz.org\/hbr\/?p=1135\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Bugs of the day, Thursday 2013-03-21&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts\/1135"}],"collection":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1135"}],"version-history":[{"count":6,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts\/1135\/revisions"}],"predecessor-version":[{"id":1164,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts\/1135\/revisions\/1164"}],"wp:attachment":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}