regedit: Use the heap_*() functions in edit.c where possible.
Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
c193bffb3e
commit
6238cd46f2
@ -101,7 +101,6 @@ static BOOL change_dword_base(HWND hwndDlg, BOOL toHex)
|
|||||||
|
|
||||||
static INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
static INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
WCHAR* valueData;
|
|
||||||
HWND hwndValue;
|
HWND hwndValue;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
@ -122,12 +121,10 @@ static INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L
|
|||||||
case IDOK:
|
case IDOK:
|
||||||
if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
|
if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
|
||||||
len = GetWindowTextLengthW(hwndValue);
|
len = GetWindowTextLengthW(hwndValue);
|
||||||
if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(WCHAR)))) {
|
stringValueData = heap_xrealloc(stringValueData, (len + 1) * sizeof(WCHAR));
|
||||||
stringValueData = valueData;
|
if (!GetWindowTextW(hwndValue, stringValueData, len + 1))
|
||||||
if (!GetWindowTextW(hwndValue, stringValueData, len + 1))
|
*stringValueData = 0;
|
||||||
*stringValueData = 0;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
case IDCANCEL:
|
case IDCANCEL:
|
||||||
EndDialog(hwndDlg, wParam);
|
EndDialog(hwndDlg, wParam);
|
||||||
@ -159,13 +156,13 @@ static INT_PTR CALLBACK bin_modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wPara
|
|||||||
case IDOK:
|
case IDOK:
|
||||||
params = (struct edit_params *)GetWindowLongPtrW(hwndDlg, DWLP_USER);
|
params = (struct edit_params *)GetWindowLongPtrW(hwndDlg, DWLP_USER);
|
||||||
cbData = SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, 0, 0);
|
cbData = SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, 0, 0);
|
||||||
pData = HeapAlloc(GetProcessHeap(), 0, cbData);
|
pData = heap_xalloc(cbData);
|
||||||
|
|
||||||
if (pData)
|
if (pData)
|
||||||
{
|
{
|
||||||
SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, (WPARAM)cbData, (LPARAM)pData);
|
SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, (WPARAM)cbData, (LPARAM)pData);
|
||||||
lRet = RegSetValueExW(params->hKey, params->lpszValueName, 0, REG_BINARY, pData, cbData);
|
lRet = RegSetValueExW(params->hKey, params->lpszValueName, 0, REG_BINARY, pData, cbData);
|
||||||
HeapFree(GetProcessHeap(), 0, pData);
|
heap_free(pData);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
lRet = ERROR_OUTOFMEMORY;
|
lRet = ERROR_OUTOFMEMORY;
|
||||||
@ -206,7 +203,7 @@ static LPWSTR read_value(HWND hwnd, HKEY hKey, LPCWSTR valueName, DWORD *lpType,
|
|||||||
if (lRet == ERROR_FILE_NOT_FOUND && !valueName) { /* no default value here, make it up */
|
if (lRet == ERROR_FILE_NOT_FOUND && !valueName) { /* no default value here, make it up */
|
||||||
if (len) *len = 1;
|
if (len) *len = 1;
|
||||||
if (lpType) *lpType = REG_SZ;
|
if (lpType) *lpType = REG_SZ;
|
||||||
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR));
|
buffer = heap_xalloc(sizeof(WCHAR));
|
||||||
*buffer = '\0';
|
*buffer = '\0';
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
@ -214,10 +211,7 @@ static LPWSTR read_value(HWND hwnd, HKEY hKey, LPCWSTR valueName, DWORD *lpType,
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if ( *lpType == REG_DWORD ) valueDataLen = sizeof(DWORD);
|
if ( *lpType == REG_DWORD ) valueDataLen = sizeof(DWORD);
|
||||||
if (!(buffer = HeapAlloc(GetProcessHeap(), 0, valueDataLen+sizeof(WCHAR)))) {
|
buffer = heap_xalloc(valueDataLen + sizeof(WCHAR));
|
||||||
error_code_messagebox(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
lRet = RegQueryValueExW(hKey, valueName, 0, 0, (LPBYTE)buffer, &valueDataLen);
|
lRet = RegQueryValueExW(hKey, valueName, 0, 0, (LPBYTE)buffer, &valueDataLen);
|
||||||
if (lRet != ERROR_SUCCESS) {
|
if (lRet != ERROR_SUCCESS) {
|
||||||
error_code_messagebox(hwnd, IDS_BAD_VALUE, valueName);
|
error_code_messagebox(hwnd, IDS_BAD_VALUE, valueName);
|
||||||
@ -229,7 +223,7 @@ static LPWSTR read_value(HWND hwnd, HKEY hKey, LPCWSTR valueName, DWORD *lpType,
|
|||||||
return buffer;
|
return buffer;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
heap_free(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,7 +301,7 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
|
|||||||
if (lRet == ERROR_SUCCESS) result = TRUE;
|
if (lRet == ERROR_SUCCESS) result = TRUE;
|
||||||
else error_code_messagebox(hwnd, IDS_SET_VALUE_FAILED);
|
else error_code_messagebox(hwnd, IDS_SET_VALUE_FAILED);
|
||||||
}
|
}
|
||||||
HeapFree(GetProcessHeap(), 0, valueA);
|
heap_free(valueA);
|
||||||
}
|
}
|
||||||
} else if ( type == REG_BINARY ) {
|
} else if ( type == REG_BINARY ) {
|
||||||
struct edit_params params;
|
struct edit_params params;
|
||||||
@ -325,8 +319,7 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
|
|||||||
for ( i = 0, count = 0; i < len - 1; i++)
|
for ( i = 0, count = 0; i < len - 1; i++)
|
||||||
if ( !stringValueData[i] && stringValueData[i + 1] )
|
if ( !stringValueData[i] && stringValueData[i + 1] )
|
||||||
count++;
|
count++;
|
||||||
tmpValueData = HeapAlloc( GetProcessHeap(), 0, ( len + count ) * sizeof(WCHAR));
|
tmpValueData = heap_xalloc((len + count) * sizeof(WCHAR));
|
||||||
if ( !tmpValueData ) goto done;
|
|
||||||
|
|
||||||
for ( i = 0, j = 0; i < len - 1; i++)
|
for ( i = 0, j = 0; i < len - 1; i++)
|
||||||
{
|
{
|
||||||
@ -339,15 +332,14 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
|
|||||||
tmpValueData[j++] = stringValueData[i];
|
tmpValueData[j++] = stringValueData[i];
|
||||||
}
|
}
|
||||||
tmpValueData[j] = stringValueData[i];
|
tmpValueData[j] = stringValueData[i];
|
||||||
HeapFree( GetProcessHeap(), 0, stringValueData);
|
heap_free(stringValueData);
|
||||||
stringValueData = tmpValueData;
|
stringValueData = tmpValueData;
|
||||||
tmpValueData = NULL;
|
tmpValueData = NULL;
|
||||||
|
|
||||||
if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_MULTI_STRING), hwnd, modify_dlgproc) == IDOK)
|
if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_MULTI_STRING), hwnd, modify_dlgproc) == IDOK)
|
||||||
{
|
{
|
||||||
len = lstrlenW( stringValueData );
|
len = lstrlenW( stringValueData );
|
||||||
tmpValueData = HeapAlloc( GetProcessHeap(), 0, (len + 2) * sizeof(WCHAR));
|
tmpValueData = heap_xalloc((len + 2) * sizeof(WCHAR));
|
||||||
if ( !tmpValueData ) goto done;
|
|
||||||
|
|
||||||
for ( i = 0, j = 0; i < len - 1; i++)
|
for ( i = 0, j = 0; i < len - 1; i++)
|
||||||
{
|
{
|
||||||
@ -363,7 +355,7 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
|
|||||||
tmpValueData[j++] = stringValueData[i];
|
tmpValueData[j++] = stringValueData[i];
|
||||||
tmpValueData[j++] = 0;
|
tmpValueData[j++] = 0;
|
||||||
tmpValueData[j++] = 0;
|
tmpValueData[j++] = 0;
|
||||||
HeapFree( GetProcessHeap(), 0, stringValueData);
|
heap_free(stringValueData);
|
||||||
stringValueData = tmpValueData;
|
stringValueData = tmpValueData;
|
||||||
|
|
||||||
lRet = RegSetValueExW(hKey, valueName, 0, type, (LPBYTE)stringValueData, j * sizeof(WCHAR));
|
lRet = RegSetValueExW(hKey, valueName, 0, type, (LPBYTE)stringValueData, j * sizeof(WCHAR));
|
||||||
@ -379,13 +371,13 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
|
|||||||
{
|
{
|
||||||
int index = SendMessageW(g_pChildWnd->hListWnd, LVM_GETNEXTITEM, -1,
|
int index = SendMessageW(g_pChildWnd->hListWnd, LVM_GETNEXTITEM, -1,
|
||||||
MAKELPARAM(LVNI_FOCUSED | LVNI_SELECTED, 0));
|
MAKELPARAM(LVNI_FOCUSED | LVNI_SELECTED, 0));
|
||||||
HeapFree(GetProcessHeap(), 0, stringValueData);
|
heap_free(stringValueData);
|
||||||
stringValueData = read_value(hwnd, hKey, valueName, &type, &len);
|
stringValueData = read_value(hwnd, hKey, valueName, &type, &len);
|
||||||
format_value_data(g_pChildWnd->hListWnd, index, type, stringValueData, len);
|
format_value_data(g_pChildWnd->hListWnd, index, type, stringValueData, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
HeapFree(GetProcessHeap(), 0, stringValueData);
|
heap_free(stringValueData);
|
||||||
stringValueData = NULL;
|
stringValueData = NULL;
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return result;
|
return result;
|
||||||
@ -535,7 +527,7 @@ BOOL RenameValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR oldName, LPC
|
|||||||
result = TRUE;
|
result = TRUE;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
HeapFree(GetProcessHeap(), 0, value);
|
heap_free(value);
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -559,7 +551,7 @@ BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCWSTR keyPath, LPCWSTR newName)
|
|||||||
} else {
|
} else {
|
||||||
LPWSTR srcSubKey_copy;
|
LPWSTR srcSubKey_copy;
|
||||||
|
|
||||||
parentPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(keyPath)+1)*sizeof(WCHAR));
|
parentPath = heap_xalloc((lstrlenW(keyPath) + 1) * sizeof(WCHAR));
|
||||||
lstrcpyW(parentPath, keyPath);
|
lstrcpyW(parentPath, keyPath);
|
||||||
srcSubKey_copy = strrchrW(parentPath, '\\');
|
srcSubKey_copy = strrchrW(parentPath, '\\');
|
||||||
*srcSubKey_copy = 0;
|
*srcSubKey_copy = 0;
|
||||||
@ -604,7 +596,7 @@ done:
|
|||||||
RegCloseKey(destKey);
|
RegCloseKey(destKey);
|
||||||
if (parentKey) {
|
if (parentKey) {
|
||||||
RegCloseKey(parentKey);
|
RegCloseKey(parentKey);
|
||||||
HeapFree(GetProcessHeap(), 0, parentPath);
|
heap_free(parentPath);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ void *heap_xalloc(size_t size)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *heap_xrealloc(void *buf, size_t size)
|
void *heap_xrealloc(void *buf, size_t size)
|
||||||
{
|
{
|
||||||
void *new_buf;
|
void *new_buf;
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ void __cdecl error_exit(unsigned int id, ...);
|
|||||||
|
|
||||||
char *GetMultiByteString(const WCHAR *strW);
|
char *GetMultiByteString(const WCHAR *strW);
|
||||||
void *heap_xalloc(size_t size);
|
void *heap_xalloc(size_t size);
|
||||||
|
void *heap_xrealloc(void *buf, size_t size);
|
||||||
BOOL heap_free(void *buf);
|
BOOL heap_free(void *buf);
|
||||||
BOOL import_registry_file(FILE *reg_file);
|
BOOL import_registry_file(FILE *reg_file);
|
||||||
void delete_registry_key(WCHAR *reg_key_name);
|
void delete_registry_key(WCHAR *reg_key_name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user