{"id":9203,"date":"2011-11-03T07:00:00","date_gmt":"2011-11-03T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2011\/11\/03\/weve-traced-the-call-and-its-coming-from-inside-the-house-a-function-call-that-always-fails\/"},"modified":"2011-11-03T07:00:00","modified_gmt":"2011-11-03T07:00:00","slug":"weve-traced-the-call-and-its-coming-from-inside-the-house-a-function-call-that-always-fails","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20111103-00\/?p=9203","title":{"rendered":"We&#039;ve traced the call and it&#039;s coming from inside the house: A function call that always fails"},"content":{"rendered":"<p>\nA customer reported that they had a problem with a particular function\nadded in Windows&nbsp;7.\nThe tricky bit was that the function was used only on very high-end\nhardware,\nnot the sort of thing your average developer has lying around.\n<\/p>\n<pre>\nGROUP_AFFINITY GroupAffinity;\n... code that initializes the GroupAffinity structure ...\nif (!SetThreadGroupAffinity(hThread, &amp;GrouAffinity, NULL));\n{\n printf(\"SetThreadGroupAffinity failed: <a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2010\/01\/27\/9953807.aspx\">%d<\/a>\\n\", GetLastError());\n return FALSE;\n}\n<\/pre>\n<p>\nThe customer reported that the function always failed\nwith error 122 (<code>ERROR_INSUFFICIENT_BUFFER<\/code>)\neven though the buffer seems perfectly valid.\n<\/p>\n<p>\nSince most of us don&#8217;t have machines with more than 64 processors,\nwe couldn&#8217;t run the code on our own machines to see what happens.\nPeople asked some clarifying questions,\nlike whether this code is compiled 32-bit or 64-bit\n(thinking that maybe there is\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/05\/19\/10013611.aspx\">\nan issue with the emulation layer<\/a>),\nuntil somebody noticed that there was a stray semicolon at the end\nof the <code>if<\/code> statement.\n<\/p>\n<p>\nThe customer was naturally embarrassed, but was gracious enough to\nadmit that, yup, removing the semicolon fixed the problem.\n<\/p>\n<p>\nThis reminds me of an incident many years ago.\nI was having a horrible time debugging a simple loop.\nIt looked like the compiler was on drugs and was simply\nignoring my loop conditions and always dropping out of the loop.\nAt wit&#8217;s end, I asked a colleague to come to my office and\nserve as a second set of eyes.\nI talked him through the code as I single-stepped:\n<\/p>\n<p>\n&#8220;Okay, so we set up the loop here&#8230;&#8221;\n<\/p>\n<pre>\nNODE pn = GetActiveNode();\n<\/pre>\n<p>\n&#8220;And we enter the loop, continuing while the node still needs processing.&#8221;\n<\/p>\n<pre>\nif (pn-&gt;NeedsProcessing())\n{\n<\/pre>\n<p>\n&#8220;Okay, we entered the loop.\nNow we realign the skew rods on the node.&#8221;\n<\/p>\n<pre>\n pn-&gt;RealignSkewRods();\n<\/pre>\n<p>\n&#8220;If the treadle is splayed, we need to calibrate the node against it.&#8221;\n<\/p>\n<pre>\n if (IsSplayed()) pn-&gt;Recalibrate(this);\n<\/pre>\n<p>\n&#8220;And then we loop back to see if there is more work to be done\non this node.&#8221;\n<\/p>\n<pre>\n}\n<\/pre>\n<p>\n&#8220;But look, even though the node needs processing\n&laquo;view node members&raquo;, we don&#8217;t loop back.\nWe just drop out of the loop.\nWhat&#8217;s going on?&#8221;\n<\/p>\n<p>\n&mdash; <i>Um, that&#8217;s an <code>if<\/code> statement up there,\nnot a <code>while<\/code> statement.<\/i><\/p>\n<p>\nA moment of silence while I process this piece of information.\n<\/p>\n<p>\n&#8220;All right then, sorry to bother you, hey,\nhow about that sporting event last night, huh?&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer reported that they had a problem with a particular function added in Windows&nbsp;7. The tricky bit was that the function was used only on very high-end hardware, not the sort of thing your average developer has lying around. GROUP_AFFINITY GroupAffinity; &#8230; code that initializes the GroupAffinity structure &#8230; if (!SetThreadGroupAffinity(hThread, &amp;GrouAffinity, NULL)); { [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-9203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer reported that they had a problem with a particular function added in Windows&nbsp;7. The tricky bit was that the function was used only on very high-end hardware, not the sort of thing your average developer has lying around. GROUP_AFFINITY GroupAffinity; &#8230; code that initializes the GroupAffinity structure &#8230; if (!SetThreadGroupAffinity(hThread, &amp;GrouAffinity, NULL)); { [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/9203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=9203"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/9203\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=9203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=9203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=9203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}