From: Hugh McMaster hugh.mcmaster@outlook.com
This bug was exposed by 3b1faf59f60c2e5d91321fd8998dd81d90a13e11
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/regedit/edit.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/programs/regedit/edit.c b/programs/regedit/edit.c index c19ef1506fa..47ce233039e 100644 --- a/programs/regedit/edit.c +++ b/programs/regedit/edit.c @@ -443,6 +443,7 @@ BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, DWORD valueType, LPW LONG lRet = ERROR_SUCCESS; WCHAR newValue[256]; UINT64 value = 0; + DWORD size_bytes; BOOL result = FALSE; int valueNum, index; HKEY hKey; @@ -466,15 +467,34 @@ BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, DWORD valueType, LPW error_code_messagebox(hwnd, IDS_CREATE_VALUE_FAILED); goto done; } - - lRet = RegSetValueExW(hKey, valueName, 0, valueType, (BYTE *)&value, sizeof(value)); + + switch (valueType) + { + case REG_DWORD: + case REG_DWORD_BIG_ENDIAN: + size_bytes = sizeof(DWORD); + break; + case REG_QWORD: + size_bytes = sizeof(UINT64); + break; + case REG_BINARY: + size_bytes = 0; + break; + case REG_MULTI_SZ: + size_bytes = 2 * sizeof(WCHAR); + break; + default: /* REG_NONE, REG_SZ, REG_EXPAND_SZ */ + size_bytes = sizeof(WCHAR); + } + + lRet = RegSetValueExW(hKey, valueName, 0, valueType, (BYTE *)&value, size_bytes); if (lRet) { error_code_messagebox(hwnd, IDS_CREATE_VALUE_FAILED); goto done; }
/* Add the new item to the listview */ - index = AddEntryToList(g_pChildWnd->hListWnd, valueName, valueType, (BYTE *)&value, sizeof(value), -1); + index = AddEntryToList(g_pChildWnd->hListWnd, valueName, valueType, (BYTE *)&value, size_bytes, -1); item.state = LVIS_FOCUSED | LVIS_SELECTED; item.stateMask = LVIS_FOCUSED | LVIS_SELECTED; SendMessageW(g_pChildWnd->hListWnd, LVM_SETITEMSTATE, index, (LPARAM)&item);
From: Hugh McMaster hugh.mcmaster@outlook.com
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/regedit/listview.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/programs/regedit/listview.c b/programs/regedit/listview.c index e314862ee6f..7841f244202 100644 --- a/programs/regedit/listview.c +++ b/programs/regedit/listview.c @@ -122,7 +122,7 @@ void format_value_data(HWND hwndLV, int index, DWORD type, void *data, DWORD siz { UINT64 value = *(UINT64 *)data; WCHAR buf[64]; - swprintf(buf, ARRAY_SIZE(buf), L"0x%08Ix (%Iu)", value, value); + swprintf(buf, ARRAY_SIZE(buf), L"0x%08llx (%llIu)", value, value); ListView_SetItemTextW(hwndLV, index, 2, buf); break; }
in first patch: - %llIu doesn't exist, I suppose you meant %llu... I'd suggest using %I64x and %I64u instead (IIRC %llu isn't supported in all versions of msvcrt on Windows)
(and yes it's a pain that mingw doesn't support __attribute__(format) for wide chars, that should have generated warnings here)
It's actually two Ls and I, not triple L. If `%llu` might cause an issue, I'll update the MR to use `%I64u`.