[PATCH 3/3] regedit: Re-implement convertHexToDWord() (v4)

Hugh McMaster hugh.mcmaster at outlook.com
Tue Apr 11 08:11:54 CDT 2017


Changes since version 3:
* Use Unicode only
* Minor clean-ups

Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
 programs/regedit/regproc.c       | 31 ++++++++++++++++++++++++-------
 programs/regedit/tests/regedit.c | 14 +++++++-------
 2 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c
index e0049c6..bfaed37 100644
--- a/programs/regedit/regproc.c
+++ b/programs/regedit/regproc.c
@@ -146,15 +146,32 @@ static char* GetMultiByteStringN(const WCHAR* strW, int chars, DWORD* len)
  */
 static BOOL convertHexToDWord(WCHAR* str, DWORD *dw)
 {
-    char buf[9];
-    char dummy;
+    BOOL ret = FALSE;
+    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 exit;
+
+    p = str;
+    while (isxdigitW(*p))
+    {
+        count++;
+        p++;
     }
-    return TRUE;
+    if (count > 8) goto exit;
+
+    end = p;
+    while (*p == ' ' || *p == '\t') p++;
+    if (*p && *p != ';') goto exit;
+
+    *end = 0;
+    *dw = strtoulW(str, &end, 16);
+    ret = TRUE;
+
+    exit:
+    if (!ret) output_message(STRING_INVALID_HEX);
+    return ret;
 }
 
 /******************************************************************************
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);
-- 
2.7.4




More information about the wine-patches mailing list