Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/add.c | 15 +++++++-------- programs/reg/delete.c | 8 ++++---- programs/reg/export.c | 45 +++++++++++++++++++++---------------------- programs/reg/import.c | 43 ++++++++++++++++++++--------------------- programs/reg/query.c | 42 ++++++++++++++++++++-------------------- programs/reg/reg.c | 35 +++++---------------------------- programs/reg/reg.h | 4 +--- 7 files changed, 81 insertions(+), 111 deletions(-)
diff --git a/programs/reg/add.c b/programs/reg/add.c index 054023df7ab..3d0a509b4f0 100644 --- a/programs/reg/add.c +++ b/programs/reg/add.c @@ -17,7 +17,6 @@ */
#include <errno.h> -#include <stdlib.h> #include "reg.h"
static DWORD wchar_get_type(const WCHAR *type_name) @@ -64,7 +63,7 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW case REG_EXPAND_SZ: { *reg_count = (lstrlenW(data) + 1) * sizeof(WCHAR); - out_data = heap_xalloc(*reg_count); + out_data = malloc(*reg_count); lstrcpyW((LPWSTR)out_data,data); break; } @@ -80,7 +79,7 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW break; } *reg_count = sizeof(DWORD); - out_data = heap_xalloc(*reg_count); + out_data = malloc(*reg_count); ((LPDWORD)out_data)[0] = val; break; } @@ -89,7 +88,7 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW BYTE hex0, hex1; int i = 0, destByteIndex = 0, datalen = lstrlenW(data); *reg_count = ((datalen + datalen % 2) / 2) * sizeof(BYTE); - out_data = heap_xalloc(*reg_count); + out_data = malloc(*reg_count); if(datalen % 2) { hex1 = hexchar_to_byte(data[i++]); @@ -108,7 +107,7 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW break; no_hex_data: /* cleanup, print error */ - heap_free(out_data); + free(out_data); output_message(STRING_MISSING_HEXDATA); out_data = NULL; break; @@ -116,7 +115,7 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW case REG_MULTI_SZ: { int i, destindex, len = lstrlenW(data); - WCHAR *buffer = heap_xalloc((len + 2) * sizeof(WCHAR)); + WCHAR *buffer = malloc((len + 2) * sizeof(WCHAR));
for (i = 0, destindex = 0; i < len; i++, destindex++) { @@ -132,7 +131,7 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW
if (destindex && !buffer[destindex - 1] && (!buffer[destindex] || destindex == 1)) { - heap_free(buffer); + free(buffer); output_message(STRING_INVALID_STRING); return NULL; } @@ -201,7 +200,7 @@ int reg_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty, }
RegSetValueExW(key, value_name, 0, reg_type, reg_data, reg_count); - heap_free(reg_data); + free(reg_data); }
RegCloseKey(key); diff --git a/programs/reg/delete.c b/programs/reg/delete.c index e0730e5c12f..6ead3fc6919 100644 --- a/programs/reg/delete.c +++ b/programs/reg/delete.c @@ -65,7 +65,7 @@ int reg_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name, WCHAR *value_name; LONG rc;
- value_name = heap_xalloc(max_value_len * sizeof(WCHAR)); + value_name = malloc(max_value_len * sizeof(WCHAR));
while (1) { @@ -76,7 +76,7 @@ int reg_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name, rc = RegDeleteValueW(key, value_name); if (rc != ERROR_SUCCESS) { - heap_free(value_name); + free(value_name); RegCloseKey(key); output_message(STRING_VALUEALL_FAILED, key_name); return 1; @@ -85,11 +85,11 @@ int reg_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name, else if (rc == ERROR_MORE_DATA) { max_value_len *= 2; - value_name = heap_xrealloc(value_name, max_value_len * sizeof(WCHAR)); + value_name = realloc(value_name, max_value_len * sizeof(WCHAR)); } else break; } - heap_free(value_name); + free(value_name); } else if (value_name || value_empty) { diff --git a/programs/reg/export.c b/programs/reg/export.c index 8ce1945a693..30f01c8b94f 100644 --- a/programs/reg/export.c +++ b/programs/reg/export.c @@ -17,7 +17,6 @@ */
#include <stdio.h> -#include <stdlib.h> #include "reg.h"
static void write_file(HANDLE hFile, const WCHAR *str) @@ -42,7 +41,7 @@ static WCHAR *escape_string(WCHAR *str, size_t str_len, size_t *line_len) escape_count++; }
- buf = heap_xalloc((str_len + escape_count + 1) * sizeof(WCHAR)); + buf = malloc((str_len + escape_count + 1) * sizeof(WCHAR));
for (i = 0, pos = 0; i < str_len; i++, pos++) { @@ -87,11 +86,11 @@ static size_t export_value_name(HANDLE hFile, WCHAR *name, size_t len) if (name && *name) { WCHAR *str = escape_string(name, len, &line_len); - WCHAR *buf = heap_xalloc((line_len + 4) * sizeof(WCHAR)); + WCHAR *buf = malloc((line_len + 4) * sizeof(WCHAR)); line_len = swprintf(buf, line_len + 4, quoted_fmt, str); write_file(hFile, buf); - heap_free(buf); - heap_free(str); + free(buf); + free(str); } else { @@ -111,16 +110,16 @@ static void export_string_data(WCHAR **buf, WCHAR *data, size_t size) if (size) len = size / sizeof(WCHAR) - 1; str = escape_string(data, len, &line_len); - *buf = heap_xalloc((line_len + 3) * sizeof(WCHAR)); + *buf = malloc((line_len + 3) * sizeof(WCHAR)); swprintf(*buf, line_len + 3, fmt, str); - heap_free(str); + free(str); }
static void export_dword_data(WCHAR **buf, DWORD *data) { static const WCHAR fmt[] = {'d','w','o','r','d',':','%','0','8','x',0};
- *buf = heap_xalloc(15 * sizeof(WCHAR)); + *buf = malloc(15 * sizeof(WCHAR)); swprintf(*buf, 15, fmt, *data); }
@@ -137,10 +136,10 @@ static size_t export_hex_data_type(HANDLE hFile, DWORD type) } else { - WCHAR *buf = heap_xalloc(15 * sizeof(WCHAR)); + WCHAR *buf = malloc(15 * sizeof(WCHAR)); line_len = swprintf(buf, 15, hexp_fmt, type); write_file(hFile, buf); - heap_free(buf); + free(buf); }
return line_len; @@ -160,7 +159,7 @@ static void export_hex_data(HANDLE hFile, WCHAR **buf, DWORD type, if (!size) return;
num_commas = size - 1; - *buf = heap_xalloc(size * 3 * sizeof(WCHAR)); + *buf = malloc(size * 3 * sizeof(WCHAR));
for (i = 0, pos = 0; i < size; i++) { @@ -217,7 +216,7 @@ static void export_data(HANDLE hFile, WCHAR *value_name, DWORD value_len, if (size || type == REG_SZ) { write_file(hFile, buf); - heap_free(buf); + free(buf); }
export_newline(hFile); @@ -228,10 +227,10 @@ static void export_key_name(HANDLE hFile, WCHAR *name) static const WCHAR fmt[] = {'\r','\n','[','%','s',']','\r','\n',0}; WCHAR *buf;
- buf = heap_xalloc((lstrlenW(name) + 7) * sizeof(WCHAR)); + buf = malloc((lstrlenW(name) + 7) * sizeof(WCHAR)); swprintf(buf, lstrlenW(name) + 7, fmt, name); write_file(hFile, buf); - heap_free(buf); + free(buf); }
static int export_registry_data(HANDLE hFile, HKEY key, WCHAR *path) @@ -247,8 +246,8 @@ static int export_registry_data(HANDLE hFile, HKEY key, WCHAR *path)
export_key_name(hFile, path);
- value_name = heap_xalloc(max_value_len * sizeof(WCHAR)); - data = heap_xalloc(max_data_bytes); + value_name = malloc(max_value_len * sizeof(WCHAR)); + data = malloc(max_data_bytes);
i = 0; for (;;) @@ -267,21 +266,21 @@ static int export_registry_data(HANDLE hFile, HKEY key, WCHAR *path) if (data_size > max_data_bytes) { max_data_bytes = data_size; - data = heap_xrealloc(data, max_data_bytes); + data = realloc(data, max_data_bytes); } else { max_value_len *= 2; - value_name = heap_xrealloc(value_name, max_value_len * sizeof(WCHAR)); + value_name = realloc(value_name, max_value_len * sizeof(WCHAR)); } } else break; }
- heap_free(data); - heap_free(value_name); + free(data); + free(value_name);
- subkey_name = heap_xalloc(MAX_SUBKEY_LEN * sizeof(WCHAR)); + subkey_name = malloc(MAX_SUBKEY_LEN * sizeof(WCHAR));
path_len = lstrlenW(path);
@@ -298,13 +297,13 @@ static int export_registry_data(HANDLE hFile, HKEY key, WCHAR *path) export_registry_data(hFile, subkey, subkey_path); RegCloseKey(subkey); } - heap_free(subkey_path); + free(subkey_path); i++; } else break; }
- heap_free(subkey_name); + free(subkey_name); return 0; }
diff --git a/programs/reg/import.c b/programs/reg/import.c index 13e54e6a69a..93d6d46aef9 100644 --- a/programs/reg/import.c +++ b/programs/reg/import.c @@ -18,7 +18,6 @@
#include <errno.h> #include <stdio.h> -#include <stdlib.h> #include "reg.h" #include <wine/debug.h>
@@ -31,7 +30,7 @@ static WCHAR *GetWideString(const char *strA) WCHAR *strW; int len = MultiByteToWideChar(CP_ACP, 0, strA, -1, NULL, 0);
- strW = heap_xalloc(len * sizeof(WCHAR)); + strW = malloc(len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, strA, -1, strW, len); return strW; } @@ -45,7 +44,7 @@ static WCHAR *GetWideStringN(const char *strA, int size, DWORD *len) WCHAR *strW; *len = MultiByteToWideChar(CP_ACP, 0, strA, size, NULL, 0);
- strW = heap_xalloc(*len * sizeof(WCHAR)); + strW = malloc(*len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, strA, size, strW, *len); return strW; } @@ -192,7 +191,7 @@ static BOOL convert_hex_csv_to_hex(struct parser *parser, WCHAR **str)
/* The worst case is 1 digit + 1 comma per byte */ size = ((lstrlenW(*str) + 1) / 2) + parser->data_size; - parser->data = heap_xrealloc(parser->data, size); + parser->data = realloc(parser->data, size);
s = *str; d = (BYTE *)parser->data + parser->data_size; @@ -358,7 +357,7 @@ static void close_key(struct parser *parser) { if (parser->hkey) { - heap_free(parser->key_name); + free(parser->key_name); parser->key_name = NULL;
RegCloseKey(parser->hkey); @@ -383,7 +382,7 @@ static LONG open_key(struct parser *parser, WCHAR *path)
if (res == ERROR_SUCCESS) { - parser->key_name = heap_xalloc((lstrlenW(path) + 1) * sizeof(WCHAR)); + parser->key_name = malloc((lstrlenW(path) + 1) * sizeof(WCHAR)); lstrcpyW(parser->key_name, path); } else @@ -395,7 +394,7 @@ static LONG open_key(struct parser *parser, WCHAR *path) static void free_parser_data(struct parser *parser) { if (parser->parse_type == REG_DWORD || parser->parse_type == REG_BINARY) - heap_free(parser->data); + free(parser->data);
parser->data = NULL; parser->data_size = 0; @@ -429,7 +428,7 @@ static void prepare_hex_string_data(struct parser *parser)
parser->data = GetWideStringN(parser->data, parser->data_size, &parser->data_size); parser->data_size *= sizeof(WCHAR); - heap_free(data); + free(data); } } } @@ -482,12 +481,12 @@ static WCHAR *header_state(struct parser *parser, WCHAR *pos)
if (!parser->is_unicode) { - header = heap_xalloc((lstrlenW(line) + 3) * sizeof(WCHAR)); + header = malloc((lstrlenW(line) + 3) * sizeof(WCHAR)); header[0] = parser->two_wchars[0]; header[1] = parser->two_wchars[1]; lstrcpyW(header + 2, line); parser->reg_version = parse_file_header(header); - heap_free(header); + free(header); } else parser->reg_version = parse_file_header(line);
@@ -627,7 +626,7 @@ static WCHAR *delete_key_state(struct parser *parser, WCHAR *pos) /* handler for parser DEFAULT_VALUE_NAME state */ static WCHAR *default_value_name_state(struct parser *parser, WCHAR *pos) { - heap_free(parser->value_name); + free(parser->value_name); parser->value_name = NULL;
set_state(parser, DATA_START); @@ -639,14 +638,14 @@ static WCHAR *quoted_value_name_state(struct parser *parser, WCHAR *pos) { WCHAR *val_name = pos, *p;
- heap_free(parser->value_name); + free(parser->value_name); parser->value_name = NULL;
if (!unescape_string(val_name, &p)) goto invalid;
/* copy the value name in case we need to parse multiple lines and the buffer is overwritten */ - parser->value_name = heap_xalloc((lstrlenW(val_name) + 1) * sizeof(WCHAR)); + parser->value_name = malloc((lstrlenW(val_name) + 1) * sizeof(WCHAR)); lstrcpyW(parser->value_name, val_name);
set_state(parser, DATA_START); @@ -757,7 +756,7 @@ static WCHAR *dword_data_state(struct parser *parser, WCHAR *pos) { WCHAR *line = pos;
- parser->data = heap_xalloc(sizeof(DWORD)); + parser->data = malloc(sizeof(DWORD));
if (!convert_hex_to_dword(line, parser->data)) goto invalid; @@ -879,14 +878,14 @@ static WCHAR *get_lineA(FILE *fp) static char *buf, *next; char *line;
- heap_free(lineW); + free(lineW);
if (!fp) goto cleanup;
if (!size) { size = REG_VAL_BUF_SIZE; - buf = heap_xalloc(size); + buf = malloc(size); *buf = 0; next = buf; } @@ -903,7 +902,7 @@ static WCHAR *get_lineA(FILE *fp) if (size - len < 3) { size *= 2; - buf = heap_xrealloc(buf, size); + buf = realloc(buf, size); } if (!(count = fread(buf + len, 1, size - len - 1, fp))) { @@ -925,7 +924,7 @@ static WCHAR *get_lineA(FILE *fp)
cleanup: lineW = NULL; - if (size) heap_free(buf); + free(buf); size = 0; return NULL; } @@ -941,7 +940,7 @@ static WCHAR *get_lineW(FILE *fp) if (!size) { size = REG_VAL_BUF_SIZE; - buf = heap_xalloc(size * sizeof(WCHAR)); + buf = malloc(size * sizeof(WCHAR)); *buf = 0; next = buf; } @@ -959,7 +958,7 @@ static WCHAR *get_lineW(FILE *fp) if (size - len < 3) { size *= 2; - buf = heap_xrealloc(buf, size * sizeof(WCHAR)); + buf = realloc(buf, size * sizeof(WCHAR)); } if (!(count = fread(buf + len, sizeof(WCHAR), size - len - 1, fp))) { @@ -978,7 +977,7 @@ static WCHAR *get_lineW(FILE *fp) }
cleanup: - if (size) heap_free(buf); + free(buf); size = 0; return NULL; } @@ -1036,7 +1035,7 @@ int reg_import(int argc, WCHAR *argvW[]) if (parser.reg_version == REG_VERSION_INVALID) goto error;
- heap_free(parser.value_name); + free(parser.value_name); close_key(&parser);
fclose(fp); diff --git a/programs/reg/query.c b/programs/reg/query.c index b24edb2f0b2..6ab518c91d9 100644 --- a/programs/reg/query.c +++ b/programs/reg/query.c @@ -41,7 +41,7 @@ static WCHAR *reg_data_to_wchar(DWORD type, const BYTE *src, DWORD size_bytes) { case REG_SZ: case REG_EXPAND_SZ: - buffer = heap_xalloc(size_bytes); + buffer = malloc(size_bytes); lstrcpyW(buffer, (WCHAR *)src); break; case REG_NONE: @@ -50,7 +50,7 @@ static WCHAR *reg_data_to_wchar(DWORD type, const BYTE *src, DWORD size_bytes) WCHAR *ptr; static const WCHAR fmt[] = {'%','0','2','X',0};
- buffer = heap_xalloc((size_bytes * 2 + 1) * sizeof(WCHAR)); + buffer = malloc((size_bytes * 2 + 1) * sizeof(WCHAR)); ptr = buffer; for (i = 0; i < size_bytes; i++) ptr += swprintf(ptr, 3, fmt, src[i]); @@ -63,7 +63,7 @@ static WCHAR *reg_data_to_wchar(DWORD type, const BYTE *src, DWORD size_bytes) const int zero_x_dword = 10; static const WCHAR fmt[] = {'0','x','%','x',0};
- buffer = heap_xalloc((zero_x_dword + 1) * sizeof(WCHAR)); + buffer = malloc((zero_x_dword + 1) * sizeof(WCHAR)); swprintf(buffer, zero_x_dword + 1, fmt, *(DWORD *)src); break; } @@ -76,13 +76,13 @@ static WCHAR *reg_data_to_wchar(DWORD type, const BYTE *src, DWORD size_bytes)
if (size_bytes <= two_wchars) { - buffer = heap_xalloc(sizeof(WCHAR)); + buffer = malloc(sizeof(WCHAR)); *buffer = 0; return buffer; }
tmp_size = size_bytes - two_wchars; /* exclude both null terminators */ - buffer = heap_xalloc(tmp_size * 2 + sizeof(WCHAR)); + buffer = malloc(tmp_size * 2 + sizeof(WCHAR)); len = tmp_size / sizeof(WCHAR);
for (i = 0, destindex = 0; i < len; i++, destindex++) @@ -123,7 +123,7 @@ static void output_value(const WCHAR *value_name, DWORD type, BYTE *data, DWORD { reg_data = reg_data_to_wchar(type, data, data_size); output_string(fmt, reg_data); - heap_free(reg_data); + free(reg_data); } else { @@ -146,7 +146,7 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse) WCHAR *subkey_name, *subkey_path; HKEY subkey;
- data = heap_xalloc(max_data_bytes); + data = malloc(max_data_bytes);
for (;;) { @@ -155,7 +155,7 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse) if (rc == ERROR_MORE_DATA) { max_data_bytes = data_size; - data = heap_xrealloc(data, max_data_bytes); + data = realloc(data, max_data_bytes); } else break; } @@ -168,7 +168,7 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse) num_values_found++; }
- heap_free(data); + free(data);
if (!recurse) { @@ -185,7 +185,7 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse) return 0; }
- subkey_name = heap_xalloc(MAX_SUBKEY_LEN * sizeof(WCHAR)); + subkey_name = malloc(MAX_SUBKEY_LEN * sizeof(WCHAR));
path_len = lstrlenW(path);
@@ -202,13 +202,13 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse) query_value(subkey, value_name, subkey_path, recurse); RegCloseKey(subkey); } - heap_free(subkey_path); + free(subkey_path); i++; } else break; }
- heap_free(subkey_name); + free(subkey_name); return 0; }
@@ -227,8 +227,8 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse)
output_string(fmt, path);
- value_name = heap_xalloc(max_value_len * sizeof(WCHAR)); - data = heap_xalloc(max_data_bytes); + value_name = malloc(max_value_len * sizeof(WCHAR)); + data = malloc(max_data_bytes);
i = 0; for (;;) @@ -246,24 +246,24 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse) if (data_size > max_data_bytes) { max_data_bytes = data_size; - data = heap_xrealloc(data, max_data_bytes); + data = realloc(data, max_data_bytes); } else { max_value_len *= 2; - value_name = heap_xrealloc(value_name, max_value_len * sizeof(WCHAR)); + value_name = realloc(value_name, max_value_len * sizeof(WCHAR)); } } else break; }
- heap_free(data); - heap_free(value_name); + free(data); + free(value_name);
if (i || recurse) output_string(newlineW);
- subkey_name = heap_xalloc(MAX_SUBKEY_LEN * sizeof(WCHAR)); + subkey_name = malloc(MAX_SUBKEY_LEN * sizeof(WCHAR));
path_len = lstrlenW(path);
@@ -282,7 +282,7 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse) query_all(subkey, subkey_path, recurse); RegCloseKey(subkey); } - heap_free(subkey_path); + free(subkey_path); } else output_string(fmt_path, path, subkey_name); i++; @@ -290,7 +290,7 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse) else break; }
- heap_free(subkey_name); + free(subkey_name);
if (i && !recurse) output_string(newlineW); diff --git a/programs/reg/reg.c b/programs/reg/reg.c index 309d855e996..7b8dd1f37f5 100644 --- a/programs/reg/reg.c +++ b/programs/reg/reg.c @@ -16,7 +16,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
-#include <stdlib.h> #include "reg.h" #include <wine/debug.h>
@@ -69,30 +68,6 @@ const struct reg_type_rels type_rels[] = {REG_MULTI_SZ, type_multi_sz}, };
-void *heap_xalloc(size_t size) -{ - void *buf = heap_alloc(size); - if (!buf) - { - ERR("Out of memory!\n"); - exit(1); - } - return buf; -} - -void *heap_xrealloc(void *buf, size_t size) -{ - void *new_buf = heap_realloc(buf, size); - - if (!new_buf) - { - ERR("Out of memory!\n"); - exit(1); - } - - return new_buf; -} - void output_writeconsole(const WCHAR *str, DWORD wlen) { DWORD count, ret; @@ -108,11 +83,11 @@ void output_writeconsole(const WCHAR *str, DWORD wlen) * one in that case. */ len = WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, NULL, 0, NULL, NULL); - msgA = heap_xalloc(len); + msgA = malloc(len);
WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, msgA, len, NULL, NULL); WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE); - heap_free(msgA); + free(msgA); } }
@@ -233,7 +208,7 @@ WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD WCHAR *subkey_path; static const WCHAR fmt[] = {'%','s','\','%','s',0};
- subkey_path = heap_xalloc((path_len + subkey_len + 2) * sizeof(WCHAR)); + subkey_path = malloc((path_len + subkey_len + 2) * sizeof(WCHAR)); swprintf(subkey_path, path_len + subkey_len + 2, fmt, path, subkey_name);
return subkey_path; @@ -255,13 +230,13 @@ static WCHAR *get_long_key(HKEY root, WCHAR *path)
if (!path) { - long_key = heap_xalloc((len + 1) * sizeof(WCHAR)); + long_key = malloc((len + 1) * sizeof(WCHAR)); lstrcpyW(long_key, root_rels[i].long_name); return long_key; }
len += lstrlenW(path) + 1; /* add one for the backslash */ - long_key = heap_xalloc((len + 1) * sizeof(WCHAR)); + long_key = malloc((len + 1) * sizeof(WCHAR)); swprintf(long_key, len + 1, fmt, root_rels[i].long_name, path); return long_key; } diff --git a/programs/reg/reg.h b/programs/reg/reg.h index 83bcf516297..89492ae8f74 100644 --- a/programs/reg/reg.h +++ b/programs/reg/reg.h @@ -19,8 +19,8 @@ #ifndef __REG_H__ #define __REG_H__
+#include <stdlib.h> #include <windows.h> -#include <wine/heap.h> #include "resource.h"
#define MAX_SUBKEY_LEN 257 @@ -33,8 +33,6 @@ struct reg_type_rels {
extern const struct reg_type_rels type_rels[8];
-void *heap_xalloc(size_t size); -void *heap_xrealloc(void *buf, size_t size); void output_writeconsole(const WCHAR *str, DWORD wlen); void WINAPIV output_message(unsigned int id, ...); void WINAPIV output_string(const WCHAR *fmt, ...);
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/tests/add.c | 6 ++++++ programs/reg/tests/delete.c | 9 +++++++++ programs/reg/tests/query.c | 9 +++++++++ 3 files changed, 24 insertions(+)
diff --git a/programs/reg/tests/add.c b/programs/reg/tests/add.c index 6d513f14fbd..8b6f234c6d0 100644 --- a/programs/reg/tests/add.c +++ b/programs/reg/tests/add.c @@ -233,6 +233,9 @@ static void test_add(void) run_reg_exe("reg add HKCU\" KEY_BASE " /f", &r); ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+ run_reg_exe("reg add HKCU\" KEY_BASE " /f /f", &r); + todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
/* Test empty type */ @@ -291,6 +294,9 @@ static void test_add(void) ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r); verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
+ run_reg_exe("reg add HKCU\" KEY_BASE " /ve /f /ve", &r); + todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + run_reg_exe("reg add HKEY_CURRENT_USER\" KEY_BASE " /ve /d WineTEST /f", &r); ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); verify_reg(hkey, "", REG_SZ, "WineTEST", 9, 0); diff --git a/programs/reg/tests/delete.c b/programs/reg/tests/delete.c index ee2257d42c5..77d95d013c9 100644 --- a/programs/reg/tests/delete.c +++ b/programs/reg/tests/delete.c @@ -47,9 +47,18 @@ static void test_delete(void) run_reg_exe("reg delete HKCU\" KEY_BASE " /v Wine /va", &r); ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
+ run_reg_exe("reg delete HKCU\" KEY_BASE " /ve /ve", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + run_reg_exe("reg delete HKCU\" KEY_BASE " /ve /va", &r); ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
+ run_reg_exe("reg delete HKCU\" KEY_BASE " /va /va", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + + run_reg_exe("reg delete HKCU\" KEY_BASE " /v Test /ve /va", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + run_reg_exe("reg delete HKCU\" KEY_BASE " /v Wine /v Test /f", &r); ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
diff --git a/programs/reg/tests/query.c b/programs/reg/tests/query.c index afa655f8d74..fcd43a4b195 100644 --- a/programs/reg/tests/query.c +++ b/programs/reg/tests/query.c @@ -74,6 +74,12 @@ static void test_query(void) run_reg_exe("reg query HKCU\" KEY_BASE " /ve", &r); ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+ run_reg_exe("reg query HKCU\" KEY_BASE " /v Test /v Wine", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + + run_reg_exe("reg query HKCU\" KEY_BASE " /v Test /ve", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + /* Create a test subkey */ add_key(key, "Subkey", &subkey); add_value(subkey, "Test", REG_SZ, world, sizeof(world)); @@ -110,6 +116,9 @@ static void test_query(void) ok(r == REG_EXIT_SUCCESS || r == REG_EXIT_FAILURE /* WinXP */, "got exit code %d, expected 0\n", r);
+ run_reg_exe("reg query HKCU\" KEY_BASE " /s /s", &r); + todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + /* Clean-up, then query */ delete_key(key, "subkey"); close_key(key);
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/tests/add.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/programs/reg/tests/add.c b/programs/reg/tests/add.c index 8b6f234c6d0..f5d473e8887 100644 --- a/programs/reg/tests/add.c +++ b/programs/reg/tests/add.c @@ -210,7 +210,7 @@ void delete_value_(const char *file, unsigned line, const HKEY hkey, const char
static void test_add(void) { - HKEY hkey; + HKEY hkey, hsubkey; LONG err; DWORD r, dword, type, size; char buffer[22]; @@ -606,6 +606,7 @@ static void test_add(void) verify_reg(hkey, "\foo\bar", REG_SZ, "", 1, 0);
close_key(hkey); + delete_tree(HKEY_CURRENT_USER, KEY_BASE);
/* Test duplicate switches */ run_reg_exe("reg add HKCU\" KEY_BASE " /v Wine /t REG_DWORD /d 0x1 /v Test /f", &r); @@ -642,6 +643,22 @@ static void test_add(void) run_reg_exe("reg add HKCU\" KEY_BASE " /v invalid4 -", &r); ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
+ /* Test whether overwriting a registry key modifies existing keys and values */ + add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey); + add_key(hkey, "Subkey", &hsubkey); + close_key(hsubkey); + add_value(hkey, "Test1", REG_SZ, "Value1", 7); + dword = 0x123; + add_value(hkey, "Test2", REG_DWORD, &dword, sizeof(dword)); + + run_reg_exe("reg add HKCU\" KEY_BASE " /f", &r); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + + verify_key(HKEY_CURRENT_USER, KEY_BASE); + verify_key(hkey, "Subkey"); + verify_reg(hkey, "Test1", REG_SZ, "Value1", 7, 0); + verify_reg(hkey, "Test2", REG_DWORD, &dword, sizeof(dword), 0); + delete_tree(HKEY_CURRENT_USER, KEY_BASE); }
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/tests/export.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/programs/reg/tests/export.c b/programs/reg/tests/export.c index 2c7ba88fb59..5296ebb1e06 100644 --- a/programs/reg/tests/export.c +++ b/programs/reg/tests/export.c @@ -247,6 +247,11 @@ static void test_export(void) ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); ok(compare_export("file.reg", simple_test, 0), "compare_export() failed\n");
+ /* Test whether a .reg file extension is required when exporting */ + run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE " foo /y", &r); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("foo", simple_test, 0), "compare_export() failed\n"); + /* Test registry export with a complex data structure */ add_key(hkey, "Subkey1", &subkey); add_value(subkey, "Binary", REG_BINARY, "\x11\x22\x33\x44", 4);
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/reg.c | 14 +++++- programs/reg/reg.rc | 115 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 120 insertions(+), 9 deletions(-)
diff --git a/programs/reg/reg.c b/programs/reg/reg.c index 7b8dd1f37f5..53f87e1defa 100644 --- a/programs/reg/reg.c +++ b/programs/reg/reg.c @@ -109,17 +109,27 @@ static void output_formatstring(const WCHAR *fmt, __ms_va_list va_args)
void WINAPIV output_message(unsigned int id, ...) { - WCHAR fmt[1024]; + WCHAR *fmt = NULL; + int len; __ms_va_list va_args;
- if (!LoadStringW(GetModuleHandleW(NULL), id, fmt, ARRAY_SIZE(fmt))) + if (!(len = LoadStringW(GetModuleHandleW(NULL), id, (WCHAR *)&fmt, 0))) { WINE_FIXME("LoadString failed with %d\n", GetLastError()); return; } + + len++; + fmt = malloc(len * sizeof(WCHAR)); + if (!fmt) return; + + LoadStringW(GetModuleHandleW(NULL), id, fmt, len); + __ms_va_start(va_args, id); output_formatstring(fmt, va_args); __ms_va_end(va_args); + + free(fmt); }
void WINAPIV output_string(const WCHAR *fmt, ...) diff --git a/programs/reg/reg.rc b/programs/reg/reg.rc index 9d8cb882c7a..6077ace0ccb 100644 --- a/programs/reg/reg.rc +++ b/programs/reg/reg.rc @@ -29,14 +29,91 @@ STRINGTABLE STRING_USAGE, "Usage:\n\ \ REG [operation] [parameters]\n\n\ \Supported operations:\n\ -\ ADD | DELETE | IMPORT | EXPORT | QUERY\n\n\ +\ ADD | DELETE | EXPORT | IMPORT | QUERY\n\n\ \For help on a specific operation, type:\n\ \ REG [operation] /?\n\n" - STRING_ADD_USAGE, "REG ADD key_name [/v value_name | /ve] [/t type] [/s separator] [/d data] [/f]\n" - STRING_DELETE_USAGE, "REG DELETE key_name [/v value_name | /ve | /va] [/f]\n" - STRING_QUERY_USAGE, "REG QUERY key_name [/v value_name | /ve] [/s]\n" + + STRING_ADD_USAGE, "REG ADD <key> [/v value_name | /ve] [/t type] [/s separator] [/d data] [/f]\n\n\ +\ Adds a key to the registry or adds a new value to a given registry key.\n\n\ +\ <key>\n\ +\ The registry key to add or, if either [/v] or [/ve] is specified,\n\ +\ the key in which to add the new registry data.\n\n\ +\ Format: ROOT\Subkey\n\n\ +\ ROOT: A predefined registry key. This must be one of the following:\n\n\ +\ HKEY_LOCAL_MACHINE | HKLM\n\ +\ HKEY_CURRENT_USER | HKCU\n\ +\ HKEY_CLASSES_ROOT | HKCR\n\ +\ HKEY_USERS | HKU\n\ +\ HKEY_CURRENT_CONFIG | HKCC\n\n\ +\ Subkey: The full path to a registry key under a given ROOT key.\n\n\ +\ /v <value_name>\n\ +\ The name of the registry value to add.\n\n\ +\ /ve\n\ +\ Add an unnamed registry value. This option modifies the (Default)\n\ +\ registry value.\n\n\ +\ /t <type>\n\ +\ The type of data to add to the registry. If [/t] is specified,\n\ +\ <type> must be one of the following:\n\n\ +\ REG_SZ | REG_MULTI_SZ | REG_EXPAND_SZ\n\ +\ REG_DWORD | REG_BINARY | REG_NONE\n\n\ +\ If [/t] is not specified, the default data type is REG_SZ.\n\n\ +\ /s <separator>\n\ +\ The character used to separate strings in REG_MULTI_SZ data.\n\ +\ If [/s] is not specified, the default separator is \0.\n\n\ +\ /d <data>\n\ +\ The data to add to the new registry value.\n\n\ +\ /f\n\ +\ Modify the registry without prompting for confirmation.\n\n" + + STRING_DELETE_USAGE, "REG DELETE <key> [/v value_name | /ve | /va] [/f]\n\n\ +\ Deletes a registry key (including all subkeys and values), or deletes\n\ +\ one or more values from a given registry key.\n\n\ +\ <key>\n\ +\ The registry key to delete or, if one of [/v], [/ve] or [/va] is\n\ +\ specified, the registry key in which to delete one or more values.\n\n\ +\ Format: ROOT\Subkey\n\n\ +\ ROOT: A predefined registry key. This must be one of the following:\n\n\ +\ HKEY_LOCAL_MACHINE | HKLM\n\ +\ HKEY_CURRENT_USER | HKCU\n\ +\ HKEY_CLASSES_ROOT | HKCR\n\ +\ HKEY_USERS | HKU\n\ +\ HKEY_CURRENT_CONFIG | HKCC\n\n\ +\ Subkey: The full path to a registry key under a given ROOT key.\n\n\ +\ /v <value_name>\n\ +\ The name of the registry value to delete.\n\n\ +\ /ve\n\ +\ Delete an unnamed registry value. This option deletes the (Default)\n\ +\ registry value.\n\n\ +\ /va\n\ +\ Delete all values from a registry key.\n\n\ +\ /f\n\ +\ Delete a registry key (including all subkeys and values) without\n\ +\ prompting for confirmation.\n\n" + + STRING_QUERY_USAGE, "REG QUERY <key> [/v value_name | /ve] [/s]\n\n\ +\ Queries a specified registry key and lists all immediate subkeys, values\n\ +\ and data within that key. Use [/s] to recursively query each subkey.\n\n\ +\ <key>\n\ +\ The registry key to query.\n\n\ +\ Format: ROOT\Subkey\n\n\ +\ ROOT: A predefined registry key. This must be one of the following:\n\n\ +\ HKEY_LOCAL_MACHINE | HKLM\n\ +\ HKEY_CURRENT_USER | HKCU\n\ +\ HKEY_CLASSES_ROOT | HKCR\n\ +\ HKEY_USERS | HKU\n\ +\ HKEY_CURRENT_CONFIG | HKCC\n\n\ +\ Subkey: The full path to a registry key under a given ROOT key.\n\n\ +\ /v <value_name>\n\ +\ The name of the registry value to query. If neither [/v] nor [/ve] is\n\ +\ specified, all values under <key> are listed.\n\n\ +\ /ve\n\ +\ Query an unnamed registry value. This option queries the (Default)\n\ +\ registry value.\n\n\ +\ /s\n\ +\ List all registry entries under <key> and its subkeys.\n\n" + STRING_SUCCESS, "The operation completed successfully\n" - STRING_INVALID_KEY, "reg: Invalid key name\n" + STRING_INVALID_KEY, "reg: Invalid registry key\n" STRING_INVALID_CMDLINE, "reg: Invalid command line parameters\n" STRING_NO_REMOTE, "reg: Unable to access remote machine\n" STRING_CANNOT_FIND, "reg: The system was unable to find the specified registry key or value\n" @@ -62,11 +139,35 @@ STRINGTABLE STRING_REG_HELP, "Type "REG /?" for help.\n" STRING_FUNC_HELP, "Type "REG %1 /?" for help.\n" STRING_VALUE_NOT_SET, "(value not set)" - STRING_IMPORT_USAGE, "REG IMPORT file.reg\n" + + STRING_IMPORT_USAGE, "REG IMPORT <file>\n\n\ +\ Imports keys, values and data from a given file into the registry.\n\n\ +\ <file>\n\ +\ The name and path of the registry file to import.\n\n" + STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n" STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n" STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\%1!c!]\n" - STRING_EXPORT_USAGE, "REG EXPORT key_name file.reg [/y]\n" + + STRING_EXPORT_USAGE, "REG EXPORT <key> <file> [/y]\n\n\ +\ Exports a specified registry key (including all subkeys and values)\n\ +\ to a file.\n\n\ +\ <key>\n\ +\ The registry key to export.\n\n\ +\ Format: ROOT\Subkey\n\n\ +\ ROOT: A predefined registry key. This must be one of the following:\n\n\ +\ HKEY_LOCAL_MACHINE | HKLM\n\ +\ HKEY_CURRENT_USER | HKCU\n\ +\ HKEY_CLASSES_ROOT | HKCR\n\ +\ HKEY_USERS | HKU\n\ +\ HKEY_CURRENT_CONFIG | HKCC\n\n\ +\ Subkey: The full path to a registry key under a given ROOT key.\n\n\ +\ <file>\n\ +\ The name and path of the registry file that will be created.\n\ +\ This file must have a .reg extension.\n\n\ +\ /y\n\ +\ Overwrite <file> without prompting for confirmation.\n\n" + STRING_INVALID_SYSTEM_KEY, "reg: Invalid system key [%1]\n" STRING_OVERWRITE_FILE, "The file '%1' already exists. Do you want to overwrite it?" }