[master] Changes to remove gcc warnings (John Bowler)
diff --git a/ANNOUNCE b/ANNOUNCE
index e1b7523..2145c37 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -61,6 +61,14 @@
     is not defined).
   Make the "png_get_uint_16" macro return a png_uint_32 in libpng-1.4 for API
     compatibility.
+  Changes to remove gcc warnings (John Bowler)
+    Certain optional gcc warning flags resulted in warnings in libpng code.
+    With these changes only -Wconversion and -Wcast-qual cannot be turned on.
+    Changes are trivial rearrangements of code.  -Wconversion is not possible
+    for pngrutil.c (because of the widespread use of += et al on variables
+    smaller than (int) or (unsigned int)) and -Wcast-qual is not possible
+    with pngwio.c and pngwutil.c because the 'write' callback and zlib
+    compression both fail to declare their input buffers with 'const'.
 
 Send comments/corrections/commendations to glennrp at users.sourceforge.net
 or to png-mng-implement at lists.sf.net (subscription required; visit
diff --git a/CHANGES b/CHANGES
index f81a9c6..4368e12 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2713,6 +2713,14 @@
     is not defined).
   Make the "png_get_uint_16" macro return a png_uint_32 in libpng-1.4 for API
     compatibility.
+  Changes to remove gcc warnings (John Bowler)
+    Certain optional gcc warning flags resulted in warnings in libpng code.
+    With these changes only -Wconversion and -Wcast-qual cannot be turned on.
+    Changes are trivial rearrangements of code.  -Wconversion is not possible
+    for pngrutil.c (because of the widespread use of += et al on variables
+    smaller than (int) or (unsigned int)) and -Wcast-qual is not possible
+    with pngwio.c and pngwutil.c because the 'write' callback and zlib
+    compression both fail to declare their input buffers with 'const'.
 
 Send comments/corrections/commendations to glennrp at users.sourceforge.net
 or to png-mng-implement at lists.sf.net (subscription required; visit
diff --git a/pngpread.c b/pngpread.c
index e33b428..d735989 100644
--- a/pngpread.c
+++ b/pngpread.c
@@ -1109,6 +1109,8 @@
 
             break;
          }
+
+         default:
          case 6:
          {
             png_push_have_row(png_ptr, png_ptr->row_buf + 1);
diff --git a/pngread.c b/pngread.c
index f1c0dc8..b3d13e4 100644
--- a/pngread.c
+++ b/pngread.c
@@ -1,7 +1,7 @@
 
 /* pngread.c - read a PNG file
  *
- * Last changed in libpng 1.4.5 [November 20, 2010]
+ * Last changed in libpng 1.4.5 [November 21, 2010]
  * Copyright (c) 1998-2010 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@@ -502,6 +502,7 @@
                return;
             }
             break;
+
          case 1:
             if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
             {
@@ -512,6 +513,7 @@
                return;
             }
             break;
+
          case 2:
             if ((png_ptr->row_number & 0x07) != 4)
             {
@@ -522,6 +524,7 @@
                return;
             }
             break;
+
          case 3:
             if ((png_ptr->row_number & 3) || png_ptr->width < 3)
             {
@@ -532,6 +535,7 @@
                return;
             }
             break;
+
          case 4:
             if ((png_ptr->row_number & 3) != 2)
             {
@@ -542,6 +546,7 @@
                return;
             }
             break;
+
          case 5:
             if ((png_ptr->row_number & 1) || png_ptr->width < 2)
             {
@@ -552,6 +557,8 @@
                return;
             }
             break;
+
+         default:
          case 6:
             if (!(png_ptr->row_number & 1))
             {
diff --git a/pngrtran.c b/pngrtran.c
index e8d9a99..703a8c9 100644
--- a/pngrtran.c
+++ b/pngrtran.c
@@ -1,7 +1,7 @@
 
 /* pngrtran.c - transforms the data in a row for PNG readers
  *
- * Last changed in libpng 1.4.5 [November 20, 2010]
+ * Last changed in libpng 1.4.5 [November 21, 2010]
  * Copyright (c) 1998-2010 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@@ -686,6 +686,11 @@
               break;
 
       case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
+         break;
+
+      default:
+         png_error(png_ptr, "invalid error action in png_set_rgb_to_gray");
+         break;
    }
    if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
 #ifdef PNG_READ_EXPAND_SUPPORTED
@@ -828,6 +833,8 @@
                }
                break;
 
+            default:
+
             case 8:
 
             case 16:
@@ -1028,6 +1035,9 @@
                   gs = 1.0 / (png_ptr->background_gamma *
                      png_ptr->screen_gamma);
                   break;
+
+               default:
+                  png_error(png_ptr, "invalid background gamma type");
             }
 
             png_ptr->background_1.gray = (png_uint_16)(pow(
@@ -1626,6 +1636,9 @@
             }
             break;
          }
+
+         default:
+            break;
       }
       row_info->bit_depth = 8;
       row_info->pixel_depth = (png_byte)(8 * row_info->channels);
@@ -1682,6 +1695,9 @@
 
       switch (row_info->bit_depth)
       {
+         default:
+            break; 
+
          case 2:
          {
             png_bytep bp;
@@ -2798,6 +2814,9 @@
                   }
                   break;
                }
+
+               default:
+                  break;
             }
             break;
          }
@@ -3230,6 +3249,9 @@
             }
             break;
          }
+
+         default:
+            break;
       }
 
       if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
@@ -3428,6 +3450,9 @@
             }
             break;
          }
+
+         default:
+            break;
       }
    }
 }
@@ -3522,6 +3547,9 @@
                }
                break;
             }
+
+            default:
+               break;
          }
          row_info->bit_depth = 8;
          row_info->pixel_depth = 8;
@@ -3672,6 +3700,9 @@
                   }
                   break;
                }
+
+               default:
+                  break;
             }
 
             row_info->bit_depth = 8;
diff --git a/pngrutil.c b/pngrutil.c
index 3ef330e..e979d24 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -68,6 +68,11 @@
 png_uint_16 (PNGAPI
 png_get_uint_16) (png_bytep buf)
 {
+   /* ANSI-C requires an int value to accomodate at least 16 bits so this
+    * works and allows the compiler not to worry about possible narrowing
+    * on 32 bit systems.  (Pre-ANSI systems did not make integers smaller
+    * than 16 bits either.)
+    */
    unsigned int val =
        ((unsigned int)(*buf) << 8) +
        ((unsigned int)(*(buf + 1)));
diff --git a/pngwtran.c b/pngwtran.c
index 070caa5..2925a93 100644
--- a/pngwtran.c
+++ b/pngwtran.c
@@ -195,6 +195,9 @@
                *dp = (png_byte)v;
             break;
          }
+
+         default:
+            break;
       }
       row_info->bit_depth = (png_byte)bit_depth;
       row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
diff --git a/pngwutil.c b/pngwutil.c
index 19feb1d..8f7c7c2 100644
--- a/pngwutil.c
+++ b/pngwutil.c
@@ -246,10 +246,12 @@
     */
 
    /* Set up the compression buffers */
+   /* TODO: the following cast hides a potential overflow problem. */
    png_ptr->zstream.avail_in = (uInt)text_len;
+   /* NOTE: assume zlib doesn't overwrite the input */
    png_ptr->zstream.next_in = (Bytef *)text;
-   png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
-   png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
+   png_ptr->zstream.avail_out = png_ptr->zbuf_size;
+   png_ptr->zstream.next_out = png_ptr->zbuf;
 
    /* This is the same compression loop as in png_write_row() */
    do