[PATCH 2/2] regedit: Re-implement convertHextToDWord() (v3)
Hugh McMaster
hugh.mcmaster at outlook.com
Mon Apr 10 08:18:00 CDT 2017
This version supersedes the previous patch series.
Sorry for all of the noise.
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
programs/regedit/regproc.c | 35 ++++++++++++++++++++++++++++-------
programs/regedit/tests/regedit.c | 10 +++++-----
2 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c
index e0049c6..9e0ad00 100644
--- a/programs/regedit/regproc.c
+++ b/programs/regedit/regproc.c
@@ -146,15 +146,36 @@ static char* GetMultiByteStringN(const WCHAR* strW, int chars, DWORD* len)
*/
static BOOL convertHexToDWord(WCHAR* str, DWORD *dw)
{
- char buf[9];
- char dummy;
+ char *buf, *p, *end;
+ int count = 0;
+ BOOL ret = FALSE;
- 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;
+ buf = GetMultiByteString(str);
+ if (!buf) return FALSE;
+
+ while (*buf == ' ' || *buf == '\t') buf++;
+ if (!*buf) goto exit;
+
+ p = buf;
+ while (isxdigit(*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 = strtoul(buf, &end, 16);
+ ret = TRUE;
+
+ exit:
+ if (!ret) output_message(STRING_INVALID_HEX);
+ HeapFree(GetProcessHeap(), 0, buf);
+ return ret;
}
/******************************************************************************
diff --git a/programs/regedit/tests/regedit.c b/programs/regedit/tests/regedit.c
index 6695a01..bdd51a1 100644
--- a/programs/regedit/tests/regedit.c
+++ b/programs/regedit/tests/regedit.c
@@ -528,7 +528,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");
@@ -568,7 +568,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"
@@ -628,7 +628,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"
@@ -637,8 +637,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");
--
2.7.4
More information about the wine-patches
mailing list