{"id":1393,"date":"2014-03-26T07:00:00","date_gmt":"2014-03-26T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/03\/26\/can-cocreateguid-ever-return-guid_null\/"},"modified":"2014-03-26T07:00:00","modified_gmt":"2014-03-26T07:00:00","slug":"can-cocreateguid-ever-return-guid_null","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20140326-00\/?p=1393","title":{"rendered":"Can CoCreateGuid ever return GUID_NULL?"},"content":{"rendered":"<p>A customer asked whether the <code>Co&shy;Create&shy;Guid<\/code> function can ever return <code>GUID_NULL<\/code>. Their code uses <code>GUID_NULL<\/code> for special purposes, and it would be bad if that was ever returned as the GUID for an object. &#8220;Can we assume that <code>Co&shy;Create&shy;Guid<\/code> never returns <code>GUID_NULL<\/code>? Or should we test the return value against <code>GUID_NULL<\/code>, and if it is equal, then call <code>Co&shy;Create&shy;Guid<\/code> and try again?&#8221;\n Some people started running <code>Co&shy;Create&shy;Guid<\/code> a bunch of times and observing that it was spitting out type&nbsp;4 GUIDs, which will always have a 4 in the version field. Then other people started wondering whether the use of Algorithm&nbsp;4 was contractual (it isn&#8217;t). Then still other people went back to read the RFCs which cover UUIDs to see whether those documents provided any guidance.\n And then I had to step in and stop the madness.\n It is very easy to show that any UUID generator which generates <code>GUID_NULL<\/code> has failed to meet the requirement that the generated UUID be unique in space and time: If it&#8217;s equal to <code>GUID_NULL<\/code>, then it isn&#8217;t unique!\n The uniqueness requirement is that the generated GUID be different from any other valid GUID. And if it generated <code>GUID_NULL<\/code>, then it wouldn&#8217;t be different from <code>GUID_NULL<\/code>! (And <code>GUID_NULL<\/code> is a valid GUID, specifically identified in RFC4122 section 4.1.7.)\n If you&#8217;re so worried about <code>Co&shy;Create&shy;Guid<\/code> generating a duplicate <code>GUID_NULL<\/code>, why aren&#8217;t you worried about <code>Co&shy;Create&shy;Guid<\/code> generating a duplicate <code>IID_IUnknown<\/code> or <code>GUID_DEV&shy;CLASS_1394<\/code> or any of the other GUIDs that have already been generated in the past?\n In other words, no valid implementation of <code>Co&shy;Create&shy;Guid<\/code> can generate <code>GUID_NULL<\/code> because the specification for the function says that it is not allowed to generate any GUID that has been seen before.<\/p>\n<p> One of my colleagues cheekily remarked, &#8220;And even if it did generate <code>GUID_NULL<\/code> for some reason, uniqueness would require that it do so only once! (So you should try to force this bug to occur in test, and then you can be confident that it will never occur in production.)&#8221; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer asked whether the Co&shy;Create&shy;Guid function can ever return GUID_NULL. Their code uses GUID_NULL for special purposes, and it would be bad if that was ever returned as the GUID for an object. &#8220;Can we assume that Co&shy;Create&shy;Guid never returns GUID_NULL? Or should we test the return value against GUID_NULL, and if it is [&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-1393","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer asked whether the Co&shy;Create&shy;Guid function can ever return GUID_NULL. Their code uses GUID_NULL for special purposes, and it would be bad if that was ever returned as the GUID for an object. &#8220;Can we assume that Co&shy;Create&shy;Guid never returns GUID_NULL? Or should we test the return value against GUID_NULL, and if it is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1393","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=1393"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1393\/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=1393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=1393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=1393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}