Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix for error truncating registry key names #702
referenced this pull request
Sep 24, 2014
I'd say it depends on the handling of the other side. If there's a name withe a size greater than 255 chars, the question is, what does the OS do when writing to the registry? If it also simply truncates, then we should try to read these truncated key as well.
Just tried it with the following snippet (on Windows 8.1 using latest official MinGW (GCC 4.8.1)):
The key creation fails reporting "Wrong parameter" (localized).
So seems like this is yet another case of an outdated/unclear/wrong/misleading MSDN note:
Single keys must not be longer than 255 characters, the full path may be longer.
Let's face it... MSDN documentation has to be taken with a pinch of salt most of the time anyway. When they provide limits, they are what is guaranteed to work on all systems. What might work on your system (path longer than 255 characters) might not work on others, maybe because they are simply older. We don't have to push something beyond its limits just because we can
And more to the point, the patch I wrote only truncates a sub-key and not the whole path. So in that sense, it kind of corresponds to your findings. Sub-keys are, from what I understand, segments of the whole path anyway, and since the code already opens up the root key prior to browsing through the hierarchy using sub-keys, we don't make the assumption that the whole key length (including root) has to be smaller than 255. If we were really picky, we could split it into even more sub-keys so that longer paths are supported, but I think this would bring little benefit anyway since this is not a typical scenario. If you look at the base path that is common for all joysticks, it isn't that long either. So the only way for us to ever exceed 255 characters is for the OEM name to be abnormally long, and I think it is safe to assume that this does not happen that often either.