[PATCH:libSM 2/8] Move and rename temp[4] definition to reduce confusion with temp[256]

Mark Kettenis mark.kettenis at xs4all.nl
Tue Dec 6 01:10:55 PST 2011


> From: Alan Coopersmith <alan.coopersmith at oracle.com>
> Date: Mon,  5 Dec 2011 20:06:15 -0800
> 
> Both variables were locals in different scope levels of the same
> function, leading to both confusing code and gcc -Wshadow warnings:
> 
> sm_genid.c: In function 'SmsGenerateClientID':
> sm_genid.c:160:10: warning: declaration of 'temp' shadows a previous local
> 
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

One small nit; see below.

> ---
>  src/sm_genid.c |   11 ++++++-----
>  1 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/src/sm_genid.c b/src/sm_genid.c
> index a8161ff..c46a0c5 100644
> --- a/src/sm_genid.c
> +++ b/src/sm_genid.c
> @@ -157,7 +157,7 @@ SmsGenerateClientID(SmsConn smsConn)
>  
>      {
>      char* inet_addr;
> -    char temp[4], *ptr1, *ptr2;
> +    char *ptr1;
>      unsigned char decimal[4];
>      int i, len;
>      struct in_addr *haddr = NULL;
> @@ -204,7 +204,8 @@ SmsGenerateClientID(SmsConn smsConn)
>      inet_addr = inet_ntoa (*haddr);
>      for (i = 0, ptr1 = inet_addr; i < 3; i++)
>      {
> -	ptr2 = strchr (ptr1, '.');
> +	char temp4[4];
> +	char *ptr2 = strchr (ptr1, '.');

I know it's a matter of style, but I'd like to see a blank line here
to make it obvious where the variable declarations end.

>  	len = ptr2 - ptr1;
>  	if (!ptr2 || len > 3) {
>  #  if defined(IPv6) && defined(AF_INET6)
> @@ -212,9 +213,9 @@ SmsGenerateClientID(SmsConn smsConn)
>  #  endif
>  	    return (NULL);
>  	}
> -	strncpy (temp, ptr1, len);
> -	temp[len] = '\0';
> -	decimal[i] = atoi (temp);
> +	strncpy (temp4, ptr1, len);
> +	temp4[len] = '\0';
> +	decimal[i] = atoi (temp4);
>  	ptr1 = ptr2 + 1;
>      }


More information about the xorg-devel mailing list