[PATCH 2/4] regedit: Simplify parseKeyName()

Hugh McMaster hugh.mcmaster at outlook.com
Tue Apr 25 03:44:57 CDT 2017


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


More information about the wine-devel mailing list