tools: Consistently use xmalloc/xrealloc/xstrdup everywhere.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2022-02-08 18:03:23 +01:00
parent 78ef8cf443
commit 62f9bd39a2
7 changed files with 23 additions and 27 deletions

View File

@ -521,7 +521,7 @@ arg_list: arg { check_arg_attrs($1); $$ = append_var( NULL, $1 ); }
; ;
args: arg_list 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 */ /* 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 (args) LIST_FOR_EACH_ENTRY(arg, args, var_t, entry)
{ {
if (is_attr(arg->attrs, ATTR_IN) || !is_attr(arg->attrs, ATTR_OUT)) 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)) 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); begin_func = copy_var(func, strmake("Begin_%s", func->name), NULL);

View File

@ -489,8 +489,8 @@ static void init_argv0_dir( const char *argv0 )
#elif defined (__FreeBSD__) || defined(__DragonFly__) #elif defined (__FreeBSD__) || defined(__DragonFly__)
static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t path_size = PATH_MAX; size_t path_size = PATH_MAX;
char *path = malloc( path_size ); char *path = xmalloc( path_size );
if (path && !sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 )) if (!sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
dir = realpath( path, NULL ); dir = realpath( path, NULL );
free( path ); free( path );
#else #else

View File

@ -1319,15 +1319,13 @@ static void init_symbol_dumper(struct symbol_dumper* sd)
{ {
sd->depth = 0; sd->depth = 0;
sd->alloc = 16; 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) static void push_symbol_dumper(struct symbol_dumper* sd, const union codeview_symbol* sym, unsigned end)
{ {
if (!sd->stack) return; if (!sd->stack) return;
if (sd->depth >= sd->alloc && if (sd->depth >= sd->alloc) sd->stack = xrealloc(sd->stack, (sd->alloc *= 2) * sizeof(sd->stack[0]));
!(sd->stack = realloc(sd->stack, (sd->alloc *= 2) * sizeof(sd->stack[0]))))
return;
sd->stack[sd->depth].end = end; sd->stack[sd->depth].end = end;
sd->stack[sd->depth].sym = sym; sd->stack[sd->depth].sym = sym;
sd->depth++; sd->depth++;

View File

@ -490,8 +490,6 @@ static char *demangle_datatype (char **str, compound_type *ct,
iter++; iter++;
/* Apply our constraints to the base type (struct xxx *) */ /* Apply our constraints to the base type (struct xxx *) */
stripped = xstrdup (sym->arg_text [0]); 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 we're a reference, re-use the pointer already in the type */
if (!(ct->flags & CT_BY_REFERENCE)) if (!(ct->flags & CT_BY_REFERENCE))

View File

@ -657,8 +657,8 @@ static void init_argv0_dir( const char *argv0 )
#elif defined (__FreeBSD__) || defined(__DragonFly__) #elif defined (__FreeBSD__) || defined(__DragonFly__)
static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t path_size = PATH_MAX; size_t path_size = PATH_MAX;
char *path = malloc( path_size ); char *path = xmalloc( path_size );
if (path && !sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 )) if (!sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
dir = realpath( path, NULL ); dir = realpath( path, NULL );
free( path ); free( path );
#else #else
@ -1114,7 +1114,7 @@ static void build(struct options* opts)
* -xlll: lll is the language (c, c++, etc.) * -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 */ /* 'winegcc -o app xxx.exe.so' only creates the load script */
if (opts->files.count == 1 && strendswith(opts->files.str[0], ".exe.so")) 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]) switch (opts.args.str[i][1])
{ {
case 'B': case 'B':
str = strdup(option_arg); str = xstrdup(option_arg);
if (strendswith(str, "/")) str[strlen(str) - 1] = 0; if (strendswith(str, "/")) str[strlen(str) - 1] = 0;
strarray_add(&opts.prefix, str); strarray_add(&opts.prefix, str);
raw_linker_arg = 1; 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) 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; continue;
} }
if (!strcmp(Wl.str[j], "--section-alignment") && j < Wl.count - 1) 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; continue;
} }
if (!strcmp(Wl.str[j], "--file-alignment") && j < Wl.count - 1) 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; continue;
} }
if (!strcmp(Wl.str[j], "--large-address-aware")) 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) if (!strcmp(Wl.str[j], "--subsystem") && j < Wl.count - 1)
{ {
opts.subsystem = strdup( Wl.str[++j] ); opts.subsystem = xstrdup( Wl.str[++j] );
continue; continue;
} }
if (!strcmp(Wl.str[j], "--entry") && j < Wl.count - 1) 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; continue;
} }
if (!strcmp(Wl.str[j], "-delayload") && j < Wl.count - 1) 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) 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; continue;
} }
if (!strcmp(Wl.str[j], "--whole-archive") || if (!strcmp(Wl.str[j], "--whole-archive") ||
@ -1877,7 +1877,7 @@ int main(int argc, char **argv)
} }
if (!strcmp(Wl.str[j], "--out-implib")) if (!strcmp(Wl.str[j], "--out-implib"))
{ {
opts.out_implib = strdup( Wl.str[++j] ); opts.out_implib = xstrdup( Wl.str[++j] );
continue; continue;
} }
if (!strcmp(Wl.str[j], "-static")) linking = -1; if (!strcmp(Wl.str[j], "-static")) linking = -1;

View File

@ -157,8 +157,8 @@ static void init_argv0_dir( const char *argv0 )
#elif defined (__FreeBSD__) || defined(__DragonFly__) #elif defined (__FreeBSD__) || defined(__DragonFly__)
static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t path_size = PATH_MAX; size_t path_size = PATH_MAX;
char *path = malloc( path_size ); char *path = xmalloc( path_size );
if (path && !sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 )) if (!sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
dir = realpath( path, NULL ); dir = realpath( path, NULL );
free( path ); free( path );
#else #else

View File

@ -307,8 +307,8 @@ static void init_argv0_dir( const char *argv0 )
#elif defined (__FreeBSD__) || defined(__DragonFly__) #elif defined (__FreeBSD__) || defined(__DragonFly__)
static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t path_size = PATH_MAX; size_t path_size = PATH_MAX;
char *path = malloc( path_size ); char *path = xmalloc( path_size );
if (path && !sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 )) if (!sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 ))
dir = realpath( path, NULL ); dir = realpath( path, NULL );
free( path ); free( path );
#else #else
@ -401,7 +401,7 @@ static void option_callback( int optc, char *optarg )
optarg++; optarg++;
/* fall through */ /* fall through */
case 'o': case 'o':
if (!output_name) output_name = strdup(optarg); if (!output_name) output_name = xstrdup(optarg);
else error("Too many output files.\n"); else error("Too many output files.\n");
break; break;
case 'O': case 'O':