Hugh McMaster : regedit: Re-implement convertHexToDWord().
Alexandre Julliard
julliard at winehq.org
Tue Apr 11 15:31:03 CDT 2017
Module: wine
Branch: master
Commit: 0a71d4fa72038b505f621fe15ba0b02663ad93cf
URL: http://source.winehq.org/git/wine.git/?a=commit;h=0a71d4fa72038b505f621fe15ba0b02663ad93cf
Author: Hugh McMaster <hugh.mcmaster at outlook.com>
Date: Tue Apr 11 13:11:54 2017 +0000
regedit: Re-implement convertHexToDWord().
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
programs/regedit/regproc.c | 28 ++++++++++++++++++++++------
programs/regedit/tests/regedit.c | 14 +++++++-------
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c
index e0049c6..96c4564 100644
--- a/programs/regedit/regproc.c
+++ b/programs/regedit/regproc.c
@@ -146,15 +146,31 @@ static char* GetMultiByteStringN(const WCHAR* strW, int chars, DWORD* len)
*/
static BOOL convertHexToDWord(WCHAR* str, DWORD *dw)
{
- char buf[9];
- char dummy;
+ WCHAR *p, *end;
+ int count = 0;
- WideCharToMultiByte(CP_ACP, 0, str, -1, buf, 9, NULL, NULL);
- if (lstrlenW(str) > 8 || sscanf(buf, "%x%c", dw, &dummy) != 1) {
- output_message(STRING_INVALID_HEX);
- return FALSE;
+ while (*str == ' ' || *str == '\t') str++;
+ if (!*str) goto error;
+
+ p = str;
+ while (isxdigitW(*p))
+ {
+ count++;
+ p++;
}
+ if (count > 8) goto error;
+
+ end = p;
+ while (*p == ' ' || *p == '\t') p++;
+ if (*p && *p != ';') goto error;
+
+ *end = 0;
+ *dw = strtoulW(str, &end, 16);
return TRUE;
+
+error:
+ output_message(STRING_INVALID_HEX);
+ return FALSE;
}
/******************************************************************************
diff --git a/programs/regedit/tests/regedit.c b/programs/regedit/tests/regedit.c
index 515a6ed..54d20ed 100644
--- a/programs/regedit/tests/regedit.c
+++ b/programs/regedit/tests/regedit.c
@@ -530,7 +530,7 @@ static void test_invalid_import(void)
"\"Test14a\"=dword:0x123\n"
"\"Test14b\"=dword:123 456\n"
"\"Test14c\"=dword:1234 5678\n\n");
- todo_wine verify_reg_nonexist(hkey, "Test14a");
+ verify_reg_nonexist(hkey, "Test14a");
verify_reg_nonexist(hkey, "Test14b");
verify_reg_nonexist(hkey, "Test14c");
@@ -577,7 +577,7 @@ static void test_comments(void)
todo_wine verify_reg(hkey, "Wine4", REG_SZ, "Value 2", 8, 0);
verify_reg_nonexist(hkey, "Wine5");
dword = 0x2040608;
- todo_wine verify_reg(hkey, "Wine6", REG_DWORD, &dword, sizeof(dword), 0);
+ verify_reg(hkey, "Wine6", REG_DWORD, &dword, sizeof(dword), 0);
exec_import_str("REGEDIT4\n\n"
"[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
@@ -637,7 +637,7 @@ static void test_comments(void)
verify_reg_nonexist(hkey, "Wine22");
verify_reg_nonexist(hkey, "Wine23");
dword = 0x00000004;
- todo_wine verify_reg(hkey, "Wine24", REG_DWORD, &dword, sizeof(dword), 0);
+ verify_reg(hkey, "Wine24", REG_DWORD, &dword, sizeof(dword), 0);
exec_import_str("REGEDIT4\n\n"
"[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
@@ -646,8 +646,8 @@ static void test_comments(void)
"\"Wine25c\"=dword:1234#5678\n"
"\"Wine25d\"=dword:1234 #5678\n\n");
dword = 0x1234;
- todo_wine verify_reg(hkey, "Wine25a", REG_DWORD, &dword, sizeof(dword), 0);
- todo_wine verify_reg(hkey, "Wine25b", REG_DWORD, &dword, sizeof(dword), 0);
+ verify_reg(hkey, "Wine25a", REG_DWORD, &dword, sizeof(dword), 0);
+ verify_reg(hkey, "Wine25b", REG_DWORD, &dword, sizeof(dword), 0);
verify_reg_nonexist(hkey, "Wine25c");
verify_reg_nonexist(hkey, "Wine25d");
@@ -809,8 +809,8 @@ static void test_import_with_whitespace(void)
"\"Wine9a\"=dword: 00000008\n"
"\"Wine9b\"=dword:\t\t00000008\n\n");
dword = 0x00000008;
- todo_wine verify_reg(hkey, "Wine9a", REG_DWORD, &dword, sizeof(dword), 0);
- todo_wine verify_reg(hkey, "Wine9b", REG_DWORD, &dword, sizeof(dword), 0);
+ verify_reg(hkey, "Wine9a", REG_DWORD, &dword, sizeof(dword), 0);
+ verify_reg(hkey, "Wine9b", REG_DWORD, &dword, sizeof(dword), 0);
lr = RegCloseKey(hkey);
ok(lr == ERROR_SUCCESS, "RegCloseKey failed: got %d, expected 0\n", lr);
More information about the wine-cvs
mailing list