[PATCH 1/3] regedit: Simplify parseKeyName (v2)
Hugh McMaster
hugh.mcmaster at outlook.com
Tue Apr 25 08:30:56 CDT 2017
Changes since v1:
* Added length comparison between the registry class name and input
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
programs/regedit/regproc.c | 41 +++++++++++------------------------------
1 file changed, 11 insertions(+), 30 deletions(-)
diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c
index 96c4564..5dd345b 100644
--- a/programs/regedit/regproc.c
+++ b/programs/regedit/regproc.c
@@ -303,48 +303,29 @@ static int REGPROC_unescape_string(WCHAR* str)
static BOOL parseKeyName(LPWSTR lpKeyName, HKEY *hKey, LPWSTR *lpKeyPath)
{
- WCHAR* lpSlash = NULL;
- unsigned int i, len;
+ unsigned int num_class_keys, i;
if (lpKeyName == NULL)
return FALSE;
- for(i = 0; *(lpKeyName+i) != 0; i++)
- {
- if(*(lpKeyName+i) == '\\')
- {
- lpSlash = lpKeyName+i;
- break;
- }
- }
+ *lpKeyPath = strchrW(lpKeyName, '\\');
+ if (*lpKeyPath) (*lpKeyPath)++;
- if (lpSlash)
- {
- len = lpSlash-lpKeyName;
- }
- else
- {
- len = lstrlenW(lpKeyName);
- lpSlash = lpKeyName+len;
- }
*hKey = NULL;
- 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++)
+ {
+ int len = lstrlenW(reg_class_namesW[i]);
+ if (!strncmpW(lpKeyName, reg_class_namesW[i], len) &&
+ (lpKeyName[len] == 0 || lpKeyName[len] == '\\'))
+ {
*hKey = reg_class_keys[i];
break;
}
}
- if (*hKey == NULL)
- return FALSE;
-
-
- if (*lpSlash != '\0')
- lpSlash++;
- *lpKeyPath = lpSlash;
- return TRUE;
+ return (*hKey != NULL);
}
/* Globals used by the setValue() & co */
--
2.7.4
More information about the wine-patches
mailing list