(add_string): catch error from realloc
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@13381 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -307,12 +307,22 @@ arg_printusage (struct getargs *args,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
add_string(getarg_strings *s, char *value)
|
add_string(getarg_strings *s, char *value)
|
||||||
{
|
{
|
||||||
s->strings = realloc(s->strings, (s->num_strings + 1) * sizeof(*s->strings));
|
char **strings;
|
||||||
|
|
||||||
|
strings = realloc(s->strings, (s->num_strings + 1) * sizeof(*s->strings));
|
||||||
|
if (strings == NULL) {
|
||||||
|
free(s->strings);
|
||||||
|
s->strings = NULL;
|
||||||
|
s->num_strings = 0;
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
s->strings = strings;
|
||||||
s->strings[s->num_strings] = value;
|
s->strings[s->num_strings] = value;
|
||||||
s->num_strings++;
|
s->num_strings++;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -390,8 +400,7 @@ arg_match_long(struct getargs *args, size_t num_args,
|
|||||||
}
|
}
|
||||||
case arg_strings:
|
case arg_strings:
|
||||||
{
|
{
|
||||||
add_string((getarg_strings*)current->value, goptarg + 1);
|
return add_string((getarg_strings*)current->value, goptarg + 1);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
case arg_flag:
|
case arg_flag:
|
||||||
case arg_negative_flag:
|
case arg_negative_flag:
|
||||||
@@ -497,8 +506,7 @@ arg_match_short (struct getargs *args, size_t num_args,
|
|||||||
*(char**)args[k].value = goptarg;
|
*(char**)args[k].value = goptarg;
|
||||||
return 0;
|
return 0;
|
||||||
} else if(args[k].type == arg_strings) {
|
} else if(args[k].type == arg_strings) {
|
||||||
add_string((getarg_strings*)args[k].value, goptarg);
|
return add_string((getarg_strings*)args[k].value, goptarg);
|
||||||
return 0;
|
|
||||||
} else if(args[k].type == arg_double) {
|
} else if(args[k].type == arg_double) {
|
||||||
double tmp;
|
double tmp;
|
||||||
if(sscanf(goptarg, "%lf", &tmp) != 1)
|
if(sscanf(goptarg, "%lf", &tmp) != 1)
|
||||||
|
Reference in New Issue
Block a user