{"id":97965,"date":"2018-02-05T07:00:00","date_gmt":"2018-02-05T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=97965"},"modified":"2019-03-13T01:00:49","modified_gmt":"2019-03-13T08:00:49","slug":"20180205-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20180205-00\/?p=97965","title":{"rendered":"\/\/ If this happens, I am going to quit and become a barista"},"content":{"rendered":"<p>While chasing down a bug, I ran across this comment: <\/p>\n<pre>\n\/\/ Arbitrary cap on message length.\n\/\/ If you change the format string, then update this to match.\n\/\/ (Although, if we ever need to place a million icons on the desktop,\n\/\/ I am going to quit and become a barista.)\n<\/pre>\n<p>But the buffer was not big enough. Should I suggest to the developer that they check if Starbucks is hiring? <\/p>\n<p>The buffer wasn&#8217;t big enough because the format string was incorrect. <\/p>\n<pre>\nconstexpr wchar_t formatString[] = L\"(%f3.3,%f3.3)\";\nconstexpr size_t worstCaseFormat = ARRAYSIZE(L\"(000.000,000.000)\");\n<\/pre>\n<p>I guess they never looked at their log file, because the format string is wrong. For an icon at position (10, 10), the resulting log message is <tt>(10.0000003.3,10.0000003.3)<\/tt>, which is longer than the allotted worst-case string. <\/p>\n<p>That&#8217;s because the format string <code>%f3.3<\/code> is interpreted as <\/p>\n<ul>\n<li><code>%f<\/code>: A formatted floating point number,     with a default of six places after the decimal. <\/li>\n<li><code>3.3<\/code>: The literal characters <tt>3.3<\/tt>. <\/li>\n<\/ul>\n<p>The format string was intended to be <code>%3.3f<\/code>, which means a formatted floating point number with a minimum of three characters of output and exactly three places after the decimal. <\/p>\n<p>That would result in <tt>(10.000,10.000)<\/tt>. <\/p>\n<p>Note that if you ask for three places after the decimal, then you&#8217;re going to get at least four characters of output anyway, so the first <code>3<\/code> in <code>%3.3f<\/code> is meaningless. It doesn&#8217;t cause any harm, but it doesn&#8217;t do anything either. If they wanted a fixed-width format, then they could have used <cODE>%7.3f<\/code>, which would space-pad the value on the left to ensure three characters before the decimal. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Maybe you should check if Starbucks is hiring.<\/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":[26],"class_list":["post-97965","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>Maybe you should check if Starbucks is hiring.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97965","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=97965"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97965\/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=97965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=97965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=97965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}