On 02/03/2020 21:45, Donald Sharp wrote:
> In C when declaring a variable on the stack, it is assigned
> what ever happens to be on the stack at the place the variable
> is accessed in memory from previous usage.  Let's explicitly call out a
> value instead of using whatever happens to be on the stack
> at the point of creation of the sav value.
> 
> Signed-off-by: Donald Sharp <donaldshar...@gmail.com>
> ---
>  src/util.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/util.c b/src/util.c
> index f058c92..02aa76b 100644
> --- a/src/util.c
> +++ b/src/util.c
> @@ -560,7 +560,7 @@ int parse_hex(char *in, unsigned char *out, int maxlen,
>                 int j, bytes = (1 + (r - in))/2;
>                 for (j = 0; j < bytes; j++)
>                   { 
> -                   char sav = sav;
> +                   char sav = 0;
>                     if (j < bytes - 1)
>                       {
>                         sav = in[(j+1)*2];
> 

Assigning the variable to itself suppresses a false-positive compiler
warning, but any sane compiler will not emit any code for this.
Assigning zero to the variable will need code and execution time.

The existing code is arguably better, since it makes clear that the
value of sav at this point doesn't matter.

Simon.




_______________________________________________
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss

Reply via email to