Hugh McMaster hugh.mcmaster@outlook.com writes:
- for (i = 0; i < ARRAY_SIZE(reg_class_keys); i++) {
if (CompareStringW(LOCALE_USER_DEFAULT, 0, lpKeyName, len, reg_class_namesW[i], -1) == CSTR_EQUAL &&
len == lstrlenW(reg_class_namesW[i])) {
- num_class_keys = ARRAY_SIZE(reg_class_keys);
- for (i = 0; i < num_class_keys; i++)
- {
if (!strncmpW(lpKeyName, reg_class_namesW[i], lstrlenW(reg_class_namesW[i])))
{
You still need to check that the lengths match.
On Tuesday, 25 April 2017 4:33 AM, Alexandre Julliard wrote:
Hugh McMaster writes:
- for (i = 0; i < ARRAY_SIZE(reg_class_keys); i++) { - if (CompareStringW(LOCALE_USER_DEFAULT, 0, lpKeyName, len, reg_class_namesW[i], -1) == CSTR_EQUAL && - len == lstrlenW(reg_class_namesW[i])) { + num_class_keys = ARRAY_SIZE(reg_class_keys); + for (i = 0; i < num_class_keys; i++) + { + if (!strncmpW(lpKeyName, reg_class_namesW[i], lstrlenW(reg_class_namesW[i]))) + {
You still need to check that the lengths match.
Yes, sorry about that. I'll send an updated patch.
It seems to me that it would be better to check for a backslash or null-terminator at the valid string length, instead of calculating the input key length. Something like the following:
for (i = 0; i < num_class_keys; i++) { int len = lstrlenW(reg_class_namesW[i]); WCHAR wc = lpKeyName[len]; if (!strncmp(lpKeyName, reg_class_namesW[i], len) && (wc == 0 || wc == '\')) { *hKey = reg_class_keys[i]; break; } }
Is this preferable? Or do you want to use pointer arithmetic?
Hugh
Hugh McMaster hugh.mcmaster@outlook.com writes:
Yes, sorry about that. I'll send an updated patch.
It seems to me that it would be better to check for a backslash or null-terminator at the valid string length, instead of calculating the input key length. Something like the following:
for (i = 0; i < num_class_keys; i++) { int len = lstrlenW(reg_class_namesW[i]); WCHAR wc = lpKeyName[len]; if (!strncmp(lpKeyName, reg_class_namesW[i], len) && (wc == 0 || wc == '\\')) { *hKey = reg_class_keys[i]; break; } }
Is this preferable? Or do you want to use pointer arithmetic?
You can do it that way, but you can't access lpKeyName[len] before the strncmp since you don't know if the string is long enough.