[devel] Eliminate more GCC shadow warnings
diff --git a/ANNOUNCE b/ANNOUNCE
index 38dd438..93dab38 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -61,7 +61,7 @@
 
 Version 1.5.1beta06 [January 16, 2011]
   Prevent png_push_crc_skip() from hanging while reading an unknown chunk
-    or an over-large compressed zTXT chunk with the progressive reader.
+    or an over-large compressed zTXt chunk with the progressive reader.
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net:
 (subscription required; visit
diff --git a/CHANGES b/CHANGES
index e49f36e..99d0fc9 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3177,7 +3177,7 @@
 
 Version 1.5.1beta06 [January 16, 2011]
   Prevent png_push_crc_skip() from hanging while reading an unknown chunk
-    or an over-large compressed zTXT chunk with the progressive reader.
+    or an over-large compressed zTXt chunk with the progressive reader.
 
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
diff --git a/png.c b/png.c
index bd03f58..28f2edb 100644
--- a/png.c
+++ b/png.c
@@ -1792,7 +1792,7 @@
 static png_int_32
 png_log8bit(unsigned int x)
 {
-   unsigned int log = 0;
+   unsigned int lg2 = 0;
    /* Each time 'x' is multiplied by 2, 1 must be subtracted off the final log,
     * because the log is actually negate that means adding 1.  The final
     * returned value thus has the range 0 (for 255 input) to 7.994 (for 1
@@ -1803,16 +1803,16 @@
       return 0xffffffff;
 
    if ((x & 0xf0) == 0)
-      log  = 4, x <<= 4;
+      lg2  = 4, x <<= 4;
 
    if ((x & 0xc0) == 0)
-      log += 2, x <<= 2;
+      lg2 += 2, x <<= 2;
 
    if ((x & 0x80) == 0)
-      log += 1, x <<= 1;
+      lg2 += 1, x <<= 1;
 
    /* result is at most 19 bits, so this cast is safe: */
-   return (png_int_32)((log << 16) + ((png_8bit_l2[x-128]+32768)>>16));
+   return (png_int_32)((lg2 << 16) + ((png_8bit_l2[x-128]+32768)>>16));
 }
 
 /* The above gives exact (to 16 binary places) log2 values for 8 bit images,
@@ -1848,29 +1848,29 @@
 static png_int_32
 png_log16bit(png_uint_32 x)
 {
-   unsigned int log = 0;
+   unsigned int lg2 = 0;
 
    /* As above, but now the input has 16 bits. */
    if ((x &= 0xffff) == 0)
       return 0xffffffff;
 
    if ((x & 0xff00) == 0)
-      log  = 8, x <<= 8;
+      lg2  = 8, x <<= 8;
 
    if ((x & 0xf000) == 0)
-      log += 4, x <<= 4;
+      lg2 += 4, x <<= 4;
 
    if ((x & 0xc000) == 0)
-      log += 2, x <<= 2;
+      lg2 += 2, x <<= 2;
 
    if ((x & 0x8000) == 0)
-      log += 1, x <<= 1;
+      lg2 += 1, x <<= 1;
 
    /* Calculate the base logarithm from the top 8 bits as a 28 bit fractional
     * value.
     */
-   log <<= 28;
-   log += (png_8bit_l2[(x>>8)-128]+8) >> 4;
+   lg2 <<= 28;
+   lg2 += (png_8bit_l2[(x>>8)-128]+8) >> 4;
 
    /* Now we need to interpolate the factor, this requires a division by the top
     * 8 bits.  Do this with maximum precision.
@@ -1881,19 +1881,19 @@
     * the value at 1<<16 (ignoring this) will be 0 or 1; this gives us exactly
     * 16 bits to interpolate to get the low bits of the result.  Round the
     * answer.  Note that the end point values are scaled by 64 to retain overall
-    * precision and that 'log' is current scaled by an extra 12 bits, so adjust
+    * precision and that 'lg2' is current scaled by an extra 12 bits, so adjust
     * the overall scaling by 6-12.  Round at every step.
     */
    x -= 1U << 24;
 
    if (x <= 65536U) /* <= '257' */
-      log += ((23591U * (65536U-x)) + (1U << (16+6-12-1))) >> (16+6-12);
+      lg2 += ((23591U * (65536U-x)) + (1U << (16+6-12-1))) >> (16+6-12);
 
    else
-      log -= ((23499U * (x-65536U)) + (1U << (16+6-12-1))) >> (16+6-12);
+      lg2 -= ((23499U * (x-65536U)) + (1U << (16+6-12-1))) >> (16+6-12);
 
    /* Safe, because the result can't have more than 20 bits: */
-   return (png_int_32)((log + 2048) >> 12);
+   return (png_int_32)((lg2 + 2048) >> 12);
 }
 
 /* The 'exp()' case must invert the above, taking a 20 bit fixed point
@@ -1988,10 +1988,10 @@
 }
 
 static png_byte
-png_exp8bit(png_fixed_point log)
+png_exp8bit(png_fixed_point lg2)
 {
    /* Get a 32 bit value: */
-   png_uint_32 x = png_exp(log);
+   png_uint_32 x = png_exp(lg2);
 
    /* Convert the 32 bit value to 0..255 by multiplying by 256-1, note that the
     * second, rounding, step can't overflow because of the first, subtraction,
@@ -2002,10 +2002,10 @@
 }
 
 static png_uint_16
-png_exp16bit(png_fixed_point log)
+png_exp16bit(png_fixed_point lg2)
 {
    /* Get a 32 bit value: */
-   png_uint_32 x = png_exp(log);
+   png_uint_32 x = png_exp(lg2);
 
    /* Convert the 32 bit value to 0..65535 by multiplying by 65536-1: */
    x -= x >> 16;
@@ -2022,10 +2022,10 @@
          double r = floor(255*pow(value/255.,gamma_val*.00001)+.5);
          return (png_byte)r;
 #     else
-         png_int_32 log = png_log8bit(value);
+         png_int_32 lg2 = png_log8bit(value);
          png_fixed_point res;
 
-         if (png_muldiv(&res, gamma_val, log, PNG_FP_1))
+         if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1))
             return png_exp8bit(res);
 
          /* Overflow. */
@@ -2045,10 +2045,10 @@
          double r = floor(65535*pow(value/65535.,gamma_val*.00001)+.5);
          return (png_uint_16)r;
 #     else
-         png_int_32 log = png_log16bit(value);
+         png_int_32 lg2 = png_log16bit(value);
          png_fixed_point res;
 
-         if (png_muldiv(&res, gamma_val, log, PNG_FP_1))
+         if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1))
             return png_exp16bit(res);
 
          /* Overflow. */
diff --git a/pngpread.c b/pngpread.c
index 64ed7b9..28ef3af 100644
--- a/pngpread.c
+++ b/pngpread.c
@@ -585,7 +585,7 @@
       png_size_t save_size = png_ptr->save_buffer_size;
       png_uint_32 skip_length = png_ptr->skip_length;
 
-      /* We want the smaller of 'skip_length' and 'current_buffer_size', but
+      /* We want the smaller of 'skip_length' and 'save_buffer_size', but
        * they are of different types and we don't know which variable has the
        * fewest bits.  Carefully select the smaller and cast it to the type of
        * the larger - this cannot overflow.  Do not cast in the following test
@@ -609,10 +609,8 @@
       png_size_t save_size = png_ptr->current_buffer_size;
       png_uint_32 skip_length = png_ptr->skip_length;
 
-      /* We want the smaller of 'skip_length' and 'current_buffer_size', but
-       * they are of different types and we don't know which variable has the
-       * fewest bits.  Carefully select the smaller and cast it to the type of
-       * the larger - this cannot overflow.
+      /* We want the smaller of 'skip_length' and 'current_buffer_size', here,
+       * the same problem exists as above and the same solution.
        */
       if (skip_length < save_size)
          save_size = (png_size_t)skip_length;
diff --git a/pngrutil.c b/pngrutil.c
index 14e35ee..b88124c 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -1962,7 +1962,7 @@
 void /* PRIVATE */
 png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
 {
-   png_size_t slength, index;
+   png_size_t slength, i;
    int state;
 
    png_debug(1, "in png_handle_sCAL");
@@ -2019,21 +2019,21 @@
    /* Validate the ASCII numbers, need two ASCII numbers separated by
     * a '\0' and they need to fit exactly in the chunk data.
     */
-   index = 0;
+   i = 0;
    state = 0;
 
    if (png_ptr->chunkdata[1] == 45 /* negative width */ ||
-       !png_check_fp_number(png_ptr->chunkdata, slength, &state, &index) ||
-       index >= slength || png_ptr->chunkdata[index++] != 0)
+       !png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) ||
+       i >= slength || png_ptr->chunkdata[i++] != 0)
       png_warning(png_ptr, "Invalid sCAL chunk ignored: bad width format");
 
    else
    {
-      png_size_t heighti = index;
+      png_size_t heighti = i;
 
-      if (png_ptr->chunkdata[index] == 45 /* negative height */ ||
-          !png_check_fp_number(png_ptr->chunkdata, slength, &state, &index) ||
-          index != slength)
+      if (png_ptr->chunkdata[i] == 45 /* negative height */ ||
+          !png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) ||
+          i != slength)
          png_warning(png_ptr, "Invalid sCAL chunk ignored: bad height format");
 
       else
diff --git a/pngset.c b/pngset.c
index 094e8b3..ab13fae 100644
--- a/pngset.c
+++ b/pngset.c
@@ -87,7 +87,7 @@
 #ifdef PNG_gAMA_SUPPORTED
 void PNGFAPI
 png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
-    gamma)
+    file_gamma)
 {
    png_debug1(1, "in %s storage function", "gAMA");
 
@@ -98,15 +98,15 @@
     * wrong, therefore storing them (and setting PNG_INFO_gAMA)
     * must be wrong too.
     */
-   if (gamma > (png_fixed_point)PNG_UINT_31_MAX)
+   if (file_gamma > (png_fixed_point)PNG_UINT_31_MAX)
       png_warning(png_ptr, "Gamma too large, ignored");
 
-   else if (gamma <= 0)
+   else if (file_gamma <= 0)
       png_warning(png_ptr, "Negative or zero gamma ignored");
 
    else
    {
-      info_ptr->gamma = gamma;
+      info_ptr->gamma = file_gamma;
       info_ptr->valid |= PNG_INFO_gAMA;
    }
 }
diff --git a/pngvalid.c b/pngvalid.c
index 991ec5c..ff01373 100644
--- a/pngvalid.c
+++ b/pngvalid.c
@@ -238,28 +238,28 @@
 
 static unsigned int
 sample(png_const_bytep row, png_byte colour_type, png_byte bit_depth,
-    png_uint_32 x, unsigned int sample)
+    png_uint_32 x, unsigned int sample_index)
 {
-   png_uint_32 index, result;
+   png_uint_32 bit_index, result;
 
    /* Find a sample index for the desired sample: */
    x *= bit_depth;
-   index = x;
+   bit_index = x;
 
    if ((colour_type & 1) == 0) /* !palette */
    {
       if (colour_type & 2)
-         index *= 3;
+         bit_index *= 3;
 
       if (colour_type & 4)
-         index += x; /* Alpha channel */
+         bit_index += x; /* Alpha channel */
 
       if (colour_type & (2+4))
-         index += sample * bit_depth; /* Multiple channels: select one */
+         bit_index += sample_index * bit_depth; /* Multiple channels: select one */
    }
 
    /* Return the sample from the row as an integer. */
-   row += index >> 3;
+   row += bit_index >> 3;
    result = *row;
 
    if (bit_depth == 8)
@@ -269,8 +269,8 @@
       return (result << 8) + *++row;
 
    /* Less than 8 bits per sample. */
-   index &= 7;
-   return (result >> (8-index-bit_depth)) & ((1U<<bit_depth)-1);
+   bit_index &= 7;
+   return (result >> (8-bit_index-bit_depth)) & ((1U<<bit_depth)-1);
 }
 
 /* Copy a single pixel, of a given size, from one buffer to another -
@@ -2493,6 +2493,8 @@
       /* Time for a few errors, these are in various optional chunks, the
        * standard tests test the standard chunks pretty well.
        */
+#     define exception__prev exception_prev_1
+#     define exception__env exception_env_1
       Try
       {
          /* Expect this to throw: */
@@ -2516,6 +2518,8 @@
 
       Catch (fault)
          ps = fault; /* expected exit, make sure ps is not clobbered */
+#undef exception__prev
+#undef exception__env
 
       /* And clear these flags */
       ps->expect_error = 0;
@@ -3236,7 +3240,7 @@
 }
 
 static void
-gamma_modification_init(gamma_modification *me, png_modifier *pm, double gamma)
+gamma_modification_init(gamma_modification *me, png_modifier *pm, double gammad)
 {
    double g;
 
@@ -3244,7 +3248,7 @@
    me->this.chunk = CHUNK_gAMA;
    me->this.modify_fn = gamma_modify;
    me->this.add = CHUNK_PLTE;
-   g = floor(gamma * 100000 + .5);
+   g = floor(gammad * 100000 + .5);
    me->gamma = (png_fixed_point)g;
    me->this.next = pm->modifications;
    pm->modifications = &me->this;
@@ -3501,7 +3505,7 @@
 
    PNG_CONST unsigned int samples_per_pixel = (out_ct & 2U) ? 3U : 1U;
 
-   PNG_CONST double gamma = 1/(file_gamma*screen_gamma); /* Overall */
+   PNG_CONST double gamma_correction = 1/(file_gamma*screen_gamma);/* Overall */
 
    double maxerrout = 0, maxerrabs = 0, maxerrpc = 0;
    png_uint_32 y;
@@ -3527,7 +3531,8 @@
             PNG_CONST unsigned int
                isbit = id >> (in_bd-sbit);
 
-            double i, sample, encoded_sample, output, encoded_error, error;
+            double i, input_sample, encoded_sample, output;
+            double encoded_error, error;
             double es_lo, es_hi;
 
             /* First check on the 'perfect' result obtained from the
@@ -3546,7 +3551,7 @@
              * value (nevertheless the error is still recorded - it's
              * interesting ;-)
              */
-            encoded_sample = pow(i, gamma) * outmax;
+            encoded_sample = pow(i, gamma_correction) * outmax;
             encoded_error = fabs(od-encoded_sample);
 
             if (encoded_error > maxerrout)
@@ -3564,7 +3569,7 @@
              * know what it is - so assume the unencoded value is
              * perceptually linear.
              */
-            sample = pow(i, 1/file_gamma); /* In range 0..1 */
+            input_sample = pow(i, 1/file_gamma); /* In range 0..1 */
             output = od;
             output /= outmax;
             output = pow(output, screen_gamma);
@@ -3572,7 +3577,7 @@
             /* Now we have the numbers for real errors, both absolute
              * values as as a percentage of the correct value (output):
              */
-            error = fabs(sample-output);
+            error = fabs(input_sample-output);
 
             if (error > maxerrabs)
                maxerrabs = error;
@@ -3581,10 +3586,10 @@
              * quantization to dominate the percentage errors for low
              * output sample values:
              */
-            if (sample*maxpc > .5+maxabs)
+            if (input_sample*maxpc > .5+maxabs)
             {
-               double pcerr = error/sample;
-               if (pcerr > maxerrpc) maxerrpc = pcerr;
+               double percentage_error = error/input_sample;
+               if (percentage_error > maxerrpc) maxerrpc = percentage_error;
             }
 
             /* Now calculate the digitization limits for
@@ -3596,16 +3601,17 @@
              * range 0..1:
              */
             {
-               double tmp = sample * maxpc;
+               double tmp = input_sample * maxpc;
                if (tmp < maxabs) tmp = maxabs;
 
                /* Low bound - the minimum of the three: */
                es_lo = encoded_sample - maxout;
 
-               if (es_lo > 0 && sample-tmp > 0)
+               if (es_lo > 0 && input_sample-tmp > 0)
                {
-                  double l = outmax * pow(sample-tmp, 1/screen_gamma);
-                  if (l < es_lo) es_lo = l;
+                  double low_value = outmax * pow(input_sample-tmp,
+                     1/screen_gamma);
+                  if (low_value < es_lo) es_lo = low_value;
                }
 
                else
@@ -3613,10 +3619,11 @@
 
                es_hi = encoded_sample + maxout;
 
-               if (es_hi < outmax && sample+tmp < 1)
+               if (es_hi < outmax && input_sample+tmp < 1)
                {
-                  double h = outmax * pow(sample+tmp, 1/screen_gamma);
-                  if (h > es_hi) es_hi = h;
+                  double high_value = outmax * pow(input_sample+tmp,
+                     1/screen_gamma);
+                  if (high_value > es_hi) es_hi = high_value;
                }
 
                else
@@ -3645,7 +3652,7 @@
 
                   if (tmp > 0)
                   {
-                     is_lo = outmax * pow(tmp, gamma) - maxout;
+                     is_lo = outmax * pow(tmp, gamma_correction) - maxout;
                      if (is_lo < 0) is_lo = 0;
                   }
 
@@ -3656,7 +3663,7 @@
 
                   if (tmp < 1)
                   {
-                     is_hi = outmax * pow(tmp, gamma) + maxout;
+                     is_hi = outmax * pow(tmp, gamma_correction) + maxout;
                      if (is_hi > outmax) is_hi = outmax;
                   }
 
@@ -3883,15 +3890,15 @@
 
    while (next_format(&colour_type, &bit_depth))
    {
-      double gamma = 1.0;
-      while (gamma >= .4)
+      double test_gamma = 1.0;
+      while (test_gamma >= .4)
       {
          /* There's little point testing the interlacing vs non-interlacing,
           * but this can be set from the command line.
           */
          gamma_threshold_test(pm, colour_type, bit_depth, pm->interlace_type,
-            gamma, 1/gamma);
-         gamma *= .95;
+            test_gamma, 1/test_gamma);
+         test_gamma *= .95;
       }
 
       /* And a special test for sRGB */