[ccan] [PATCH 1/2] opt: always initialise values in set_llong_with_suffix()
Rusty Russell
rusty at rustcorp.com.au
Sat Jun 21 17:19:46 EST 2014
Douglas Bagnall <douglas at halo.gen.nz> writes:
> The helper API functions based on set_llong_with_suffix() left the
> value uninitialised in the case of an empty string argument. This is
> quite unlikely to have caused problem in practice, as most values will
> have already been set to a default and the non-NULL error message
> should have triggered an early exit or some other emergency action.
> Nevertheless, it caused a compiler warning on some minor version of
> GCC 4.8 which I no longer seem to have, and the complaint seemed
> reasonable at the time.
I'm guessing gcc being overzealous about potential uninitialized value?
I've applied it: it's no worse than the errno-after-strtoll case.
Thanks,
Rusty.
>
> If an empty string (or any other non-numeric value) is passed to
> strtoll(), the result is zero. As far as I know, the strtoll() call is
> only short-circuited here to form a more specific error message, not
> because there is a good reason for the empty string to be a special
> non-initialising case. So let's set it to zero.
>
> Signed-off-by: Douglas Bagnall <douglas at halo.gen.nz>
> ---
> ccan/opt/helpers.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/ccan/opt/helpers.c b/ccan/opt/helpers.c
> index 747a78e..e531a7d 100644
> --- a/ccan/opt/helpers.c
> +++ b/ccan/opt/helpers.c
> @@ -238,9 +238,10 @@ static char *set_llong_with_suffix(const char *arg, long long *ll,
> const long long base)
> {
> char *endp;
> - if (!arg[0])
> + if (!arg[0]){
> + *ll = 0;
> return arg_bad("'%s' (an empty string) is not a number", arg);
> -
> + }
> errno = 0;
> *ll = strtoll(arg, &endp, 0);
> if (errno)
> --
> 1.8.3.2
> _______________________________________________
> ccan mailing list
> ccan at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/ccan
More information about the ccan
mailing list