Alexandre Julliard : tools: Consistently use xmalloc/xrealloc/xstrdup everywhere.
Alexandre Julliard
julliard at winehq.org
Tue Feb 8 16:11:46 CST 2022
Module: wine
Branch: master
Commit: 62f9bd39a23400b674c7192ee750f45e162ac8ab
URL: https://source.winehq.org/git/wine.git/?a=commit;h=62f9bd39a23400b674c7192ee750f45e162ac8ab
Author: Alexandre Julliard <julliard at winehq.org>
Date: Tue Feb 8 18:03:23 2022 +0100
tools: Consistently use xmalloc/xrealloc/xstrdup everywhere.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
tools/widl/parser.y | 6 +++---
tools/widl/widl.c | 4 ++--
tools/winedump/msc.c | 6 ++----
tools/winedump/msmangle.c | 2 --
tools/winegcc/winegcc.c | 22 +++++++++++-----------
tools/wmc/wmc.c | 4 ++--
tools/wrc/wrc.c | 6 +++---
7 files changed, 23 insertions(+), 27 deletions(-)
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index d6ac73cbf00..9b71cbedf6d 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -521,7 +521,7 @@ arg_list: arg { check_arg_attrs($1); $$ = append_var( NULL, $1 ); }
;
args: arg_list
- | arg_list ',' ELLIPSIS { $$ = append_var( $1, make_var(strdup("...")) ); }
+ | arg_list ',' ELLIPSIS { $$ = append_var( $1, make_var(xstrdup("...")) ); }
;
/* split into two rules to get bison to resolve a tVOID conflict */
@@ -3107,9 +3107,9 @@ static void check_async_uuid(type_t *iface)
if (args) LIST_FOR_EACH_ENTRY(arg, args, var_t, entry)
{
if (is_attr(arg->attrs, ATTR_IN) || !is_attr(arg->attrs, ATTR_OUT))
- begin_args = append_var(begin_args, copy_var(arg, strdup(arg->name), arg_in_attrs));
+ begin_args = append_var(begin_args, copy_var(arg, xstrdup(arg->name), arg_in_attrs));
if (is_attr(arg->attrs, ATTR_OUT))
- finish_args = append_var(finish_args, copy_var(arg, strdup(arg->name), arg_out_attrs));
+ finish_args = append_var(finish_args, copy_var(arg, xstrdup(arg->name), arg_out_attrs));
}
begin_func = copy_var(func, strmake("Begin_%s", func->name), NULL);
diff --git a/tools/widl/widl.c b/tools/widl/widl.c
index 7686594b7d3..7b2276b0a41 100644
--- a/tools/widl/widl.c
+++ b/tools/widl/widl.c
@@ -489,8 +489,8 @@ static void init_argv0_dir( const char *argv0 )
#elif defined (__FreeBSD__) || defined(__DragonFly__)
static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t path_size = PATH_MAX;
- char *path = malloc( path_size );
- if (path && !sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
+ char *path = xmalloc( path_size );
+ if (!sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
dir = realpath( path, NULL );
free( path );
#else
diff --git a/tools/winedump/msc.c b/tools/winedump/msc.c
index 3c632ec19e9..160ed07892e 100644
--- a/tools/winedump/msc.c
+++ b/tools/winedump/msc.c
@@ -1319,15 +1319,13 @@ static void init_symbol_dumper(struct symbol_dumper* sd)
{
sd->depth = 0;
sd->alloc = 16;
- sd->stack = malloc(sd->alloc * sizeof(sd->stack[0]));
+ sd->stack = xmalloc(sd->alloc * sizeof(sd->stack[0]));
}
static void push_symbol_dumper(struct symbol_dumper* sd, const union codeview_symbol* sym, unsigned end)
{
if (!sd->stack) return;
- if (sd->depth >= sd->alloc &&
- !(sd->stack = realloc(sd->stack, (sd->alloc *= 2) * sizeof(sd->stack[0]))))
- return;
+ if (sd->depth >= sd->alloc) sd->stack = xrealloc(sd->stack, (sd->alloc *= 2) * sizeof(sd->stack[0]));
sd->stack[sd->depth].end = end;
sd->stack[sd->depth].sym = sym;
sd->depth++;
diff --git a/tools/winedump/msmangle.c b/tools/winedump/msmangle.c
index ee7b033f757..f9440c04a45 100644
--- a/tools/winedump/msmangle.c
+++ b/tools/winedump/msmangle.c
@@ -490,8 +490,6 @@ static char *demangle_datatype (char **str, compound_type *ct,
iter++;
/* Apply our constraints to the base type (struct xxx *) */
stripped = xstrdup (sym->arg_text [0]);
- if (!stripped)
- fatal ("Out of Memory");
/* If we're a reference, re-use the pointer already in the type */
if (!(ct->flags & CT_BY_REFERENCE))
diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c
index 2eb0bdbcf3b..9bee77e3b66 100644
--- a/tools/winegcc/winegcc.c
+++ b/tools/winegcc/winegcc.c
@@ -657,8 +657,8 @@ static void init_argv0_dir( const char *argv0 )
#elif defined (__FreeBSD__) || defined(__DragonFly__)
static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t path_size = PATH_MAX;
- char *path = malloc( path_size );
- if (path && !sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
+ char *path = xmalloc( path_size );
+ if (!sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
dir = realpath( path, NULL );
free( path );
#else
@@ -1114,7 +1114,7 @@ static void build(struct options* opts)
* -xlll: lll is the language (c, c++, etc.)
*/
- output_file = strdup( opts->output_name ? opts->output_name : "a.out" );
+ output_file = xstrdup( opts->output_name ? opts->output_name : "a.out" );
/* 'winegcc -o app xxx.exe.so' only creates the load script */
if (opts->files.count == 1 && strendswith(opts->files.str[0], ".exe.so"))
@@ -1648,7 +1648,7 @@ int main(int argc, char **argv)
switch (opts.args.str[i][1])
{
case 'B':
- str = strdup(option_arg);
+ str = xstrdup(option_arg);
if (strendswith(str, "/")) str[strlen(str) - 1] = 0;
strarray_add(&opts.prefix, str);
raw_linker_arg = 1;
@@ -1824,17 +1824,17 @@ int main(int argc, char **argv)
{
if (!strcmp(Wl.str[j], "--image-base") && j < Wl.count - 1)
{
- opts.image_base = strdup( Wl.str[++j] );
+ opts.image_base = xstrdup( Wl.str[++j] );
continue;
}
if (!strcmp(Wl.str[j], "--section-alignment") && j < Wl.count - 1)
{
- opts.section_align = strdup( Wl.str[++j] );
+ opts.section_align = xstrdup( Wl.str[++j] );
continue;
}
if (!strcmp(Wl.str[j], "--file-alignment") && j < Wl.count - 1)
{
- opts.file_align = strdup( Wl.str[++j] );
+ opts.file_align = xstrdup( Wl.str[++j] );
continue;
}
if (!strcmp(Wl.str[j], "--large-address-aware"))
@@ -1849,12 +1849,12 @@ int main(int argc, char **argv)
}
if (!strcmp(Wl.str[j], "--subsystem") && j < Wl.count - 1)
{
- opts.subsystem = strdup( Wl.str[++j] );
+ opts.subsystem = xstrdup( Wl.str[++j] );
continue;
}
if (!strcmp(Wl.str[j], "--entry") && j < Wl.count - 1)
{
- opts.entry_point = strdup( Wl.str[++j] );
+ opts.entry_point = xstrdup( Wl.str[++j] );
continue;
}
if (!strcmp(Wl.str[j], "-delayload") && j < Wl.count - 1)
@@ -1864,7 +1864,7 @@ int main(int argc, char **argv)
}
if (!strcmp(Wl.str[j], "--debug-file") && j < Wl.count - 1)
{
- opts.debug_file = strdup( Wl.str[++j] );
+ opts.debug_file = xstrdup( Wl.str[++j] );
continue;
}
if (!strcmp(Wl.str[j], "--whole-archive") ||
@@ -1877,7 +1877,7 @@ int main(int argc, char **argv)
}
if (!strcmp(Wl.str[j], "--out-implib"))
{
- opts.out_implib = strdup( Wl.str[++j] );
+ opts.out_implib = xstrdup( Wl.str[++j] );
continue;
}
if (!strcmp(Wl.str[j], "-static")) linking = -1;
diff --git a/tools/wmc/wmc.c b/tools/wmc/wmc.c
index f3cd8840276..7ca339fbeef 100644
--- a/tools/wmc/wmc.c
+++ b/tools/wmc/wmc.c
@@ -157,8 +157,8 @@ static void init_argv0_dir( const char *argv0 )
#elif defined (__FreeBSD__) || defined(__DragonFly__)
static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t path_size = PATH_MAX;
- char *path = malloc( path_size );
- if (path && !sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
+ char *path = xmalloc( path_size );
+ if (!sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
dir = realpath( path, NULL );
free( path );
#else
diff --git a/tools/wrc/wrc.c b/tools/wrc/wrc.c
index 41207120237..c80827127fe 100644
--- a/tools/wrc/wrc.c
+++ b/tools/wrc/wrc.c
@@ -307,8 +307,8 @@ static void init_argv0_dir( const char *argv0 )
#elif defined (__FreeBSD__) || defined(__DragonFly__)
static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t path_size = PATH_MAX;
- char *path = malloc( path_size );
- if (path && !sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
+ char *path = xmalloc( path_size );
+ if (!sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
dir = realpath( path, NULL );
free( path );
#else
@@ -401,7 +401,7 @@ static void option_callback( int optc, char *optarg )
optarg++;
/* fall through */
case 'o':
- if (!output_name) output_name = strdup(optarg);
+ if (!output_name) output_name = xstrdup(optarg);
else error("Too many output files.\n");
break;
case 'O':
More information about the wine-cvs
mailing list