Hi Guo,

On Tue, May 14, 2013 at 1:32 PM, Guo Jian <orzhvs@gmail.com> wrote:
I just found that the REG_OPTION_VOLATILE of create_key in hkcr may
have some tricks. Not surprisingly found a strange situation when
testing on windows. See my test here please :
http://newtestbot.winehq.org/JobDetails.pl?Key=932
This happens as following :
First create hkcu/software/classes/key1, then create the
hkcr/key1/subkey with REG_OPTION_VOLATILE. RegEnumKey on hkcr  will
give two 'key1'.
I tried to use RegQueryInfoKeyA to count them, also there are more
than there should be.
Why there are two duplicated keys? May it be a bug of windows? If it
is, should we design our algorithm to avoid or treat it as a normal
feature?

That's interesting. Windows might allow both a volatile and non-volatile key of the same name. Since the volatile one is kept in-memory, any values that exist in it will be discarded eventually, so any inconsistency that arises isn't the kernel's problem. That'd be my guess, at any rate: even though such a behavior has the potential to confuse application developers, since it's not the kernel's problem, it's probably an overlooked quirk.

As far as what to do with it: this is one of those nuanced, i.e. hard to decide, things with our tests.

In general, we assume that Windows's behavior is the correct behavior, unless we have strong reason to assume otherwise. We've encountered many times that even what appear to be bugs end up being relied upon by application developers.

In this case, though, I think you might have stumbled across something that's relatively rare, and unless there's an application that depends on this behavior, it might be worth ignoring for now.

Hope that helps.
--Juan