[PATCH 2/5] regedit: Re-implement convertHexToDWord()

Hugh McMaster hugh.mcmaster at outlook.com
Mon Apr 10 04:50:27 CDT 2017


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

diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c
index e0049c6..a44a733 100644
--- a/programs/regedit/regproc.c
+++ b/programs/regedit/regproc.c
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include <errno.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -146,14 +147,20 @@ static char* GetMultiByteStringN(const WCHAR* strW, int chars, DWORD* len)
  */
 static BOOL convertHexToDWord(WCHAR* str, DWORD *dw)
 {
-    char buf[9];
-    char dummy;
+    char *buf, *end;
 
-    WideCharToMultiByte(CP_ACP, 0, str, -1, buf, 9, NULL, NULL);
-    if (lstrlenW(str) > 8 || sscanf(buf, "%x%c", dw, &dummy) != 1) {
+    buf = GetMultiByteString(str);
+    if (!buf) return FALSE;
+
+    *dw = strtoul(buf, &end, 16);
+    if (*dw == ~0u && errno == ERANGE)
+    {
         output_message(STRING_INVALID_HEX);
+        HeapFree(GetProcessHeap(), 0, buf);
         return FALSE;
     }
+
+    HeapFree(GetProcessHeap(), 0, buf);
     return TRUE;
 }
 
diff --git a/programs/regedit/tests/regedit.c b/programs/regedit/tests/regedit.c
index b2dbf34..7e8666a 100644
--- a/programs/regedit/tests/regedit.c
+++ b/programs/regedit/tests/regedit.c
@@ -511,17 +511,17 @@ static void test_invalid_import(void)
                     "\"Test12b\"=dword:hello\n"
                     "\"Test12c\"=dword:123456789\n"
                     "\"Test12d\"=dword:012345678\n\n");
-    verify_reg_nonexist(hkey, "Test12a");
-    verify_reg_nonexist(hkey, "Test12b");
+    todo_wine verify_reg_nonexist(hkey, "Test12a");
+    todo_wine verify_reg_nonexist(hkey, "Test12b");
     verify_reg_nonexist(hkey, "Test12c");
-    verify_reg_nonexist(hkey, "Test12d");
+    todo_wine verify_reg_nonexist(hkey, "Test12d");
 
     exec_import_str("REGEDIT4\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test13a\"=dword:12345678abc\n"
                     "\"Test13b\"=dword:12345678 abc\n\n");
     verify_reg_nonexist(hkey, "Test13a");
-    verify_reg_nonexist(hkey, "Test13b");
+    todo_wine verify_reg_nonexist(hkey, "Test13b");
 
     exec_import_str("REGEDIT4\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
@@ -529,8 +529,8 @@ static void test_invalid_import(void)
                     "\"Test14b\"=dword:123 456\n"
                     "\"Test14c\"=dword:1234 5678\n\n");
     todo_wine verify_reg_nonexist(hkey, "Test14a");
-    verify_reg_nonexist(hkey, "Test14b");
-    verify_reg_nonexist(hkey, "Test14c");
+    todo_wine verify_reg_nonexist(hkey, "Test14b");
+    todo_wine verify_reg_nonexist(hkey, "Test14c");
 
     RegCloseKey(hkey);
 
@@ -566,9 +566,9 @@ static void test_comments(void)
                     "\"Wine6\"=dword:02040608 ;comment\n\n");
     verify_reg_nonexist(hkey, "Wine3");
     todo_wine verify_reg(hkey, "Wine4", REG_SZ, "Value 2", 8, 0);
-    verify_reg_nonexist(hkey, "Wine5");
+    todo_wine 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"
@@ -626,9 +626,9 @@ static void test_comments(void)
     verify_reg(hkey, "Wine20", REG_SZ, "Value ;comment6", 16, 0);
     verify_reg_nonexist(hkey, "Wine21");
     verify_reg_nonexist(hkey, "Wine22");
-    verify_reg_nonexist(hkey, "Wine23");
+    todo_wine 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"
@@ -637,10 +637,10 @@ 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_nonexist(hkey, "Wine25c");
-    verify_reg_nonexist(hkey, "Wine25d");
+    verify_reg(hkey, "Wine25a", REG_DWORD, &dword, sizeof(dword), 0);
+    verify_reg(hkey, "Wine25b", REG_DWORD, &dword, sizeof(dword), 0);
+    todo_wine verify_reg_nonexist(hkey, "Wine25c");
+    todo_wine verify_reg_nonexist(hkey, "Wine25d");
 
     exec_import_str("REGEDIT4\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
-- 
2.7.4




More information about the wine-patches mailing list