Module: wine Branch: master Commit: 79ff4148c2691e579ab17ce912a97d7f57627343 URL: http://source.winehq.org/git/wine.git/?a=commit;h=79ff4148c2691e579ab17ce912...
Author: Hugh McMaster hugh.mcmaster@outlook.com Date: Thu Jul 27 12:24:49 2017 +0000
regedit: Use a helper function to allocate memory and check for a valid pointer.
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
programs/regedit/regproc.c | 68 ++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 32 deletions(-)
diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c index e0393cc..4b21478 100644 --- a/programs/regedit/regproc.c +++ b/programs/regedit/regproc.c @@ -28,8 +28,11 @@ #include <io.h> #include <windows.h> #include <wine/unicode.h> +#include <wine/debug.h> #include "regproc.h"
+WINE_DEFAULT_DEBUG_CHANNEL(regedit); + #define REG_VAL_BUF_SIZE 4096
extern const WCHAR* reg_class_namesW[]; @@ -41,6 +44,17 @@ static HKEY reg_class_keys[] = {
#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*A))
+static void *heap_xalloc(size_t size) +{ + void *buf = HeapAlloc(GetProcessHeap(), 0, size); + if (!buf) + { + ERR("Out of memory!\n"); + exit(1); + } + return buf; +} + /****************************************************************************** * Allocates memory and converts input from multibyte to wide chars * Returned string must be freed by the caller @@ -52,8 +66,7 @@ static WCHAR* GetWideString(const char* strA) WCHAR* strW; int len = MultiByteToWideChar(CP_ACP, 0, strA, -1, NULL, 0);
- strW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); - CHECK_ENOUGH_MEMORY(strW); + strW = heap_xalloc(len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, strA, -1, strW, len); return strW; } @@ -71,8 +84,7 @@ static WCHAR* GetWideStringN(const char* strA, int chars, DWORD *len) WCHAR* strW; *len = MultiByteToWideChar(CP_ACP, 0, strA, chars, NULL, 0);
- strW = HeapAlloc(GetProcessHeap(), 0, *len * sizeof(WCHAR)); - CHECK_ENOUGH_MEMORY(strW); + strW = heap_xalloc(*len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, strA, chars, strW, *len); return strW; } @@ -91,8 +103,7 @@ char* GetMultiByteString(const WCHAR* strW) char* strA; int len = WideCharToMultiByte(CP_ACP, 0, strW, -1, NULL, 0, NULL, NULL);
- strA = HeapAlloc(GetProcessHeap(), 0, len); - CHECK_ENOUGH_MEMORY(strA); + strA = heap_xalloc(len); WideCharToMultiByte(CP_ACP, 0, strW, -1, strA, len, NULL, NULL); return strA; } @@ -110,8 +121,7 @@ static char* GetMultiByteStringN(const WCHAR* strW, int chars, DWORD* len) char* strA; *len = WideCharToMultiByte(CP_ACP, 0, strW, chars, NULL, 0, NULL, NULL);
- strA = HeapAlloc(GetProcessHeap(), 0, *len); - CHECK_ENOUGH_MEMORY(strA); + strA = heap_xalloc(*len); WideCharToMultiByte(CP_ACP, 0, strW, chars, strA, *len, NULL, NULL); return strA; } @@ -476,8 +486,7 @@ static LONG open_key(struct parser *parser, WCHAR *path)
if (res == ERROR_SUCCESS) { - parser->key_name = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(path) + 1) * sizeof(WCHAR)); - CHECK_ENOUGH_MEMORY(parser->key_name); + parser->key_name = heap_xalloc((lstrlenW(path) + 1) * sizeof(WCHAR)); lstrcpyW(parser->key_name, path); } else @@ -564,8 +573,7 @@ static WCHAR *header_state(struct parser *parser, WCHAR *pos)
if (!parser->is_unicode) { - header = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(line) + 3) * sizeof(WCHAR)); - CHECK_ENOUGH_MEMORY(header); + header = heap_xalloc((lstrlenW(line) + 3) * sizeof(WCHAR)); header[0] = parser->two_wchars[0]; header[1] = parser->two_wchars[1]; lstrcpyW(header + 2, line); @@ -722,8 +730,7 @@ static WCHAR *quoted_value_name_state(struct parser *parser, WCHAR *pos) goto invalid;
/* copy the value name in case we need to parse multiple lines and the buffer is overwritten */ - parser->value_name = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(val_name) + 1) * sizeof(WCHAR)); - CHECK_ENOUGH_MEMORY(parser->value_name); + parser->value_name = heap_xalloc((lstrlenW(val_name) + 1) * sizeof(WCHAR)); lstrcpyW(parser->value_name, val_name);
set_state(parser, DATA_START); @@ -834,8 +841,7 @@ static WCHAR *dword_data_state(struct parser *parser, WCHAR *pos) { WCHAR *line = pos;
- parser->data = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD)); - CHECK_ENOUGH_MEMORY(parser->data); + parser->data = heap_xalloc(sizeof(DWORD));
if (!convert_hex_to_dword(line, parser->data)) goto invalid; @@ -958,8 +964,7 @@ static WCHAR *get_lineA(FILE *fp) if (!size) { size = REG_VAL_BUF_SIZE; - buf = HeapAlloc(GetProcessHeap(), 0, size); - CHECK_ENOUGH_MEMORY(buf); + buf = heap_xalloc(size); *buf = 0; next = buf; } @@ -1016,8 +1021,7 @@ static WCHAR *get_lineW(FILE *fp) if (!size) { size = REG_VAL_BUF_SIZE; - buf = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)); - CHECK_ENOUGH_MEMORY(buf); + buf = heap_xalloc(size * sizeof(WCHAR)); *buf = 0; next = buf; } @@ -1156,7 +1160,7 @@ static WCHAR *REGPROC_escape_string(WCHAR *str, size_t str_len, size_t *line_len escape_count++; }
- buf = resize_buffer(NULL, (str_len + escape_count + 1) * sizeof(WCHAR)); + buf = heap_xalloc((str_len + escape_count + 1) * sizeof(WCHAR));
for (i = 0, pos = 0; i < str_len; i++, pos++) { @@ -1203,7 +1207,7 @@ static size_t export_value_name(FILE *fp, WCHAR *name, size_t len, BOOL unicode) if (name && *name) { WCHAR *str = REGPROC_escape_string(name, len, &line_len); - WCHAR *buf = resize_buffer(NULL, (line_len + 4) * sizeof(WCHAR)); + WCHAR *buf = heap_xalloc((line_len + 4) * sizeof(WCHAR)); line_len = sprintfW(buf, quoted_fmt, str); REGPROC_write_line(fp, buf, unicode); HeapFree(GetProcessHeap(), 0, buf); @@ -1226,7 +1230,7 @@ static void export_string_data(WCHAR **buf, WCHAR *data, size_t size)
len = size / sizeof(WCHAR) - 1; str = REGPROC_escape_string(data, len, &line_len); - *buf = resize_buffer(NULL, (line_len + 3) * sizeof(WCHAR)); + *buf = heap_xalloc((line_len + 3) * sizeof(WCHAR)); sprintfW(*buf, fmt, str); HeapFree(GetProcessHeap(), 0, str); } @@ -1235,7 +1239,7 @@ static void export_dword_data(WCHAR **buf, DWORD *data) { static const WCHAR fmt[] = {'d','w','o','r','d',':','%','0','8','x',0};
- *buf = resize_buffer(NULL, 15 * sizeof(WCHAR)); + *buf = heap_xalloc(15 * sizeof(WCHAR)); sprintfW(*buf, fmt, *data); }
@@ -1252,7 +1256,7 @@ static size_t export_hex_data_type(FILE *fp, DWORD type, BOOL unicode) } else { - WCHAR *buf = resize_buffer(NULL, 15 * sizeof(WCHAR)); + WCHAR *buf = heap_xalloc(15 * sizeof(WCHAR)); line_len = sprintfW(buf, hexp_fmt, type); REGPROC_write_line(fp, buf, unicode); HeapFree(GetProcessHeap(), 0, buf); @@ -1276,7 +1280,7 @@ static void export_hex_data(FILE *fp, WCHAR **buf, DWORD type, DWORD line_len, data = GetMultiByteStringN(data, size / sizeof(WCHAR), &size);
num_commas = size - 1; - *buf = resize_buffer(NULL, (size * 3) * sizeof(WCHAR)); + *buf = heap_xalloc(size * 3 * sizeof(WCHAR));
for (i = 0, pos = 0; i < size; i++) { @@ -1336,7 +1340,7 @@ static WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, WCHAR *subkey_path; static const WCHAR fmt[] = {'%','s','\','%','s',0};
- subkey_path = resize_buffer(NULL, (path_len + subkey_len + 2) * sizeof(WCHAR)); + subkey_path = heap_xalloc((path_len + subkey_len + 2) * sizeof(WCHAR)); sprintfW(subkey_path, fmt, path, subkey_name);
return subkey_path; @@ -1347,7 +1351,7 @@ static void export_key_name(FILE *fp, WCHAR *name, BOOL unicode) static const WCHAR fmt[] = {'\r','\n','[','%','s',']','\r','\n',0}; WCHAR *buf;
- buf = resize_buffer(NULL, (lstrlenW(name) + 7) * sizeof(WCHAR)); + buf = heap_xalloc((lstrlenW(name) + 7) * sizeof(WCHAR)); sprintfW(buf, fmt, name); REGPROC_write_line(fp, buf, unicode); HeapFree(GetProcessHeap(), 0, buf); @@ -1368,8 +1372,8 @@ static int export_registry_data(FILE *fp, HKEY key, WCHAR *path, BOOL unicode)
export_key_name(fp, path, unicode);
- value_name = resize_buffer(NULL, max_value_len * sizeof(WCHAR)); - data = resize_buffer(NULL, max_data_bytes); + value_name = heap_xalloc(max_value_len * sizeof(WCHAR)); + data = heap_xalloc(max_data_bytes);
i = 0; for (;;) @@ -1401,7 +1405,7 @@ static int export_registry_data(FILE *fp, HKEY key, WCHAR *path, BOOL unicode) HeapFree(GetProcessHeap(), 0, data); HeapFree(GetProcessHeap(), 0, value_name);
- subkey_name = resize_buffer(NULL, MAX_SUBKEY_LEN * sizeof(WCHAR)); + subkey_name = heap_xalloc(MAX_SUBKEY_LEN * sizeof(WCHAR));
path_len = lstrlenW(path);
@@ -1521,7 +1525,7 @@ static BOOL export_all(WCHAR *file_name, WCHAR *path, BOOL unicode) return FALSE; }
- class_name = resize_buffer(NULL, (lstrlenW(reg_class_namesW[i]) + 1) * sizeof(WCHAR)); + class_name = heap_xalloc((lstrlenW(reg_class_namesW[i]) + 1) * sizeof(WCHAR)); lstrcpyW(class_name, reg_class_namesW[i]);
export_registry_data(fp, classes[i], class_name, unicode);