[rtmpdump] patch: gcc -Wshadow

Howard Chu hyc at highlandsun.com
Sat Apr 9 03:11:36 CEST 2011


Peter Miller wrote:
> This patch adds the use of gcc -Wshadow, which issues warnings when a
> symbol declaration 'shadows' an earlier declaration.  This can expose
> hard-to-find bugs when you think you are using a variable from the outer
> scope, when in fact you are using the variable from the inner scope, and
> your changes to the 'outer' variable are disappearing.  This is even
> more important when developers other than the original author are
> reading the code.

Which developers are reading the code doesn't really matter. The only ones who 
matter are the ones writing it.

> Index: librtmp/hashswf.c
> --- librtmp/hashswf.c
> +++ librtmp/hashswf.c
> @@ -359,7 +359,7 @@
>   static time_t
>   make_unix_time(char *s)
>   {
> -  struct tm time;
> +  struct tm when;
>     int i, ysub = 1900, fmt = 0;
>     char *month;
>     char *n;
> @@ -375,18 +375,18 @@
>       if (*n == '-' || *n == ':')
>         *n = ' ';
>
> -  time.tm_mon = 0;
> +  when.tm_mon = 0;
>     n = strchr(s, ' ');
>     if (fmt)
>       {
>         /* Day, DD-MMM-YYYY HH:MM:SS GMT */
> -      time.tm_mday = strtol(n + 1,&n, 0);
> +      when.tm_mday = strtol(n + 1,&n, 0);
>         month = n + 1;
>         n = strchr(month, ' ');
> -      time.tm_year = strtol(n + 1,&n, 0);
> -      time.tm_hour = strtol(n + 1,&n, 0);
> -      time.tm_min = strtol(n + 1,&n, 0);
> -      time.tm_sec = strtol(n + 1, NULL, 0);
> +      when.tm_year = strtol(n + 1,&n, 0);
> +      when.tm_hour = strtol(n + 1,&n, 0);
> +      when.tm_min = strtol(n + 1,&n, 0);
> +      when.tm_sec = strtol(n + 1, NULL, 0);
>       }
>     else
>       {
> @@ -396,22 +396,22 @@
>         n = strchr(month, ' ');
>         while (isspace(*n))
>   	n++;
> -      time.tm_mday = strtol(n,&n, 0);
> -      time.tm_hour = strtol(n + 1,&n, 0);
> -      time.tm_min = strtol(n + 1,&n, 0);
> -      time.tm_sec = strtol(n + 1,&n, 0);
> -      time.tm_year = strtol(n + 1, NULL, 0);
> +      when.tm_mday = strtol(n,&n, 0);
> +      when.tm_hour = strtol(n + 1,&n, 0);
> +      when.tm_min = strtol(n + 1,&n, 0);
> +      when.tm_sec = strtol(n + 1,&n, 0);
> +      when.tm_year = strtol(n + 1, NULL, 0);
>       }
> -  if (time.tm_year>  100)
> -    time.tm_year -= ysub;
> +  if (when.tm_year>  100)
> +    when.tm_year -= ysub;
>
>     for (i = 0; i<  12; i++)
>       if (!strncasecmp(month, monthtab[i], 3))
>         {
> -	time.tm_mon = i;
> +	when.tm_mon = i;
>   	break;
>         }
> -  time.tm_isdst = 0;		/* daylight saving is never in effect in GMT */
> +  when.tm_isdst = 0;		/* daylight saving is never in effect in GMT */
>
>     /* this is normally the value of extern int timezone, but some
>      * braindead C libraries don't provide it.
> @@ -424,8 +424,8 @@
>         tzoff = (12 - tc->tm_hour) * 3600 + tc->tm_min * 60 + tc->tm_sec;
>         tzchecked = 1;
>       }
> -  res = mktime(&time);
> -  /* Unfortunately, mktime() assumes the input is in local time,
> +  res = mktime(&when);
> +  /* Unfortunately, mktime() assumes the input is in local when,
>      * not GMT, so we have to correct it here.
>      */
>     if (res != -1)

Careful programmers don't do global replace on text without reading the result.


More information about the rtmpdump mailing list