[libpng17] Imported from libpng-1.7.0beta86.tar
diff --git a/ANNOUNCE b/ANNOUNCE
index 924de18..e6b5874 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
 
-Libpng 1.7.0beta85 - December 27, 2016
+Libpng 1.7.0beta86 - December 27, 2016
 
 This is not intended to be a public release.  It will be replaced
 within a few weeks by a public version or by another test version.
@@ -9,20 +9,20 @@
 Source files with LF line endings (for Unix/Linux) and with a
 "configure" script
 
-   1.7.0beta85.tar.xz (LZMA-compressed, recommended)
-   1.7.0beta85.tar.gz
+   1.7.0beta86.tar.xz (LZMA-compressed, recommended)
+   1.7.0beta86.tar.gz
 
 Source files with CRLF line endings (for Windows), without the
 "configure" script
 
-   /scratch/glennrp/Libpng17/lp170b85.7z  (LZMA-compressed, recommended)
-   /scratch/glennrp/Libpng17/lp170b85.zip
+   /scratch/glennrp/Libpng17/lp170b86.7z  (LZMA-compressed, recommended)
+   /scratch/glennrp/Libpng17/lp170b86.zip
 
 Other information:
 
-   1.7.0beta85-README.txt
-   1.7.0beta85-LICENSE.txt
-   libpng-1.7.0beta85-*.asc (armored detached GPG signatures)
+   1.7.0beta86-README.txt
+   1.7.0beta86-LICENSE.txt
+   libpng-1.7.0beta86-*.asc (armored detached GPG signatures)
 
 Changes since the last public release (1.6.0):
 
@@ -1418,6 +1418,8 @@
     substitution of an expression itself containing a well-formed defined
     operation.
 
+Version 1.7.0beta86 [December 27, 2016]
+
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
 https://lists.sourceforge.net/lists/listinfo/png-mng-implement
diff --git a/CHANGES b/CHANGES
index 1d6e1cc..2356250 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5718,6 +5718,8 @@
     substitution of an expression itself containing a well-formed defined
     operation.
 
+Version 1.7.0beta86 [December 27, 2016]
+
 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 (subscription required; visit
 https://lists.sourceforge.net/lists/listinfo/png-mng-implement
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3ebd516..851ec5d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -697,7 +697,7 @@
 # SET UP LINKS
 if(PNG_SHARED)
   set_target_properties(png PROPERTIES
-#   VERSION 17.${PNGLIB_RELEASE}.1.7.0beta85
+#   VERSION 17.${PNGLIB_RELEASE}.1.7.0beta86
     VERSION 17.${PNGLIB_RELEASE}.0
     SOVERSION 17
     CLEAN_DIRECT_OUTPUT 1)
diff --git a/LICENSE b/LICENSE
index 1952dc7..2da1205 100644
--- a/LICENSE
+++ b/LICENSE
@@ -10,7 +10,7 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.0.7, July 1, 2000, through 1.7.0beta85, September 26, 2016, are
+libpng versions 1.0.7, July 1, 2000, through 1.7.0beta86, December 27, 2016, are
 Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are
 derived from libpng-1.0.6, and are distributed according to the same
 disclaimer and license as libpng-1.0.6 with the following individuals
@@ -109,4 +109,4 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-September 26, 2016
+December 27, 2016
diff --git a/Makefile.am b/Makefile.am
index d443c99..32a8b91 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,11 @@
-# Makefile.am:
-#   Source file for Makefile.in (and hence Makefile)
+# Makefile.am, the source file for Makefile.in (and hence Makefile), is
 #
+# Copyright (c) 2004-2016 Glenn Randers-Pehrson
+# Last changed in libpng 1.7.0 [(PENDING RELEASE)]
+#
+# This code is released under the libpng license.
+# For conditions of distribution and use, see the disclaimer
+# and license in png.h
 
 PNGLIB_BASENAME= libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@
 
diff --git a/README b/README
index 097090a..c4a0bf5 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng version 1.7.0beta85 - September 26, 2016 (shared library 17.0)
+README for libpng version 1.7.0beta86 - December 27, 2016 (shared library 17.0)
 See the note about version numbers near the top of png.h
 
 See INSTALL for instructions on how to install libpng.
diff --git a/TODO b/TODO
index b6ea77d..ba7f6d0 100644
--- a/TODO
+++ b/TODO
@@ -7,7 +7,7 @@
 cHRM transformation.
 Remove setjmp/longjmp usage in favor of returning error codes. As a start on
   this, minimize the use of png_error(), replacing them with
-  png_warning(); return(0; or similar.
+  png_warning(); return(0); or similar.
 Palette creation.
 Add "grayscale->palette" transformation and "palette->grayscale" detection.
 Improved dithering.
@@ -24,8 +24,8 @@
   background and doing rgb-to-gray transformation.
 Investigate pre-incremented loop counters and other loop constructions.
 Add interpolated method of handling interlacing.
-Switch to the simpler zlib (zlib/libpng) license if legally possible.
 Extend pngvalid.c to validate more of the libpng transformations.
 Refactor preprocessor conditionals to compile entire statements
+Quiet compiler warnings (mostly -Wconversion warnings).
 
 */
diff --git a/configure.ac b/configure.ac
index 3bcc54d..140e329 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,13 @@
 # configure.ac
 
+# Copyright (c) 2004-2016 Glenn Randers-Pehrson
+# Last changed in libpng 1.7.0 [(PENDING RELEASE)]
+
+# This code is released under the libpng license.
+# For conditions of distribution and use, see the disclaimer
+# and license in png.h
+
+
 dnl Process this file with autoconf to produce a configure script.
 dnl
 dnl Minor upgrades (compatible ABI): increment the package version
@@ -18,7 +26,7 @@
 
 dnl Version number stuff here:
 
-AC_INIT([libpng],[1.7.0beta85],[png-mng-implement@lists.sourceforge.net])
+AC_INIT([libpng],[1.7.0beta86],[png-mng-implement@lists.sourceforge.net])
 AC_CONFIG_MACRO_DIR([scripts])
 
 # libpng does not follow GNU file name conventions (hence 'foreign')
@@ -40,7 +48,7 @@
 dnl AM_PREREQ([1.11.2])
 dnl stop configure from automagically running automake
 
-PNGLIB_VERSION=1.7.0beta85
+PNGLIB_VERSION=1.7.0beta86
 PNGLIB_MAJOR=1
 PNGLIB_MINOR=7
 PNGLIB_RELEASE=0
diff --git a/contrib/libtests/pngunknown.c b/contrib/libtests/pngunknown.c
index b27b075..aba605e 100644
--- a/contrib/libtests/pngunknown.c
+++ b/contrib/libtests/pngunknown.c
@@ -1,7 +1,7 @@
 
 /* pngunknown.c - test the read side unknown chunk handling
  *
- * Last changed in libpng 1.6.26 [(PENDING RELEASE)]
+ * Last changed in libpng 1.6.26 [October 20, 2016]
  * Copyright (c) 2015,2016 Glenn Randers-Pehrson
  * Written by John Cunningham Bowler
  *
diff --git a/contrib/tools/pngfix.c b/contrib/tools/pngfix.c
index fef1096..6da970c 100644
--- a/contrib/tools/pngfix.c
+++ b/contrib/tools/pngfix.c
@@ -2,7 +2,7 @@
  *
  * Copyright (c) 2014-2016 John Cunningham Bowler
  *
- * Last changed in libpng 1.6.26 [(PENDING RELEASE)]
+ * Last changed in libpng 1.6.26 [October 20, 2016]
  *
  * This code is released under the libpng license.
  * For conditions of distribution and use, see the disclaimer
diff --git a/decompress_chunk.c b/decompress_chunk.c
new file mode 100644
index 0000000..77700ce
--- /dev/null
+++ b/decompress_chunk.c
@@ -0,0 +1,225 @@
+png_decompress_chunk(png_structrp png_ptr,
+    png_uint_32 chunklength, png_uint_32 prefix_size,
+    png_alloc_size_t *newlength /* must be initialized to the maximum! */,
+    int terminate /*add a '\0' to the end of the uncompressed data*/)
+{
+   /* TODO: implement different limits for different types of chunk.
+    *
+    * The caller supplies *newlength set to the maximum length of the
+    * uncompressed data, but this routine allocates space for the prefix and
+    * maybe a '\0' terminator too.  We have to assume that 'prefix_size' is
+    * limited only by the maximum chunk size.
+    */
+   png_alloc_size_t limit = PNG_SIZE_MAX;
+
+#  ifdef PNG_SET_USER_LIMITS_SUPPORTED
+      if (png_ptr->user_chunk_malloc_max > 0 &&
+         png_ptr->user_chunk_malloc_max < limit)
+         limit = png_ptr->user_chunk_malloc_max;
+#  elif PNG_USER_CHUNK_MALLOC_MAX > 0
+      if (PNG_USER_CHUNK_MALLOC_MAX < limit)
+         limit = PNG_USER_CHUNK_MALLOC_MAX;
+#  endif
+
+   if (limit >= prefix_size + (terminate != 0))
+   {
+      int ret;
+
+      limit -= prefix_size + (terminate != 0);
+
+      if (limit < *newlength)
+         *newlength = limit;
+
+      /* Now try to claim the stream. */
+      ret = png_inflate_claim(png_ptr, png_ptr->chunk_name);
+
+      if (ret == Z_OK)
+      {
+         png_uint_32 lzsize = chunklength - prefix_size;
+
+         ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
+             /* input: */ png_ptr->read_buffer + prefix_size, &lzsize,
+             /* output: */ NULL, newlength);
+
+         if (ret == Z_STREAM_END)
+         {
+            /* Use 'inflateReset' here, not 'inflateReset2' because this
+             * preserves the previously decided window size (otherwise it would
+             * be necessary to store the previous window size.)  In practice
+             * this doesn't matter anyway, because png_inflate will call inflate
+             * with Z_FINISH in almost all cases, so the window will not be
+             * maintained.
+             */
+            if (inflateReset(&png_ptr->zstream) == Z_OK)
+            {
+               /* Because of the limit checks above we know that the new,
+                * expanded, size will fit in a size_t (let alone an
+                * png_alloc_size_t).  Use png_malloc_base here to avoid an
+                * extra OOM message.
+                */
+               png_alloc_size_t new_size = *newlength;
+               png_alloc_size_t buffer_size = prefix_size + new_size +
+                   (terminate != 0);
+               png_bytep text = png_voidcast(png_bytep, png_malloc_base(png_ptr,
+                   buffer_size));
+
+               if (text != NULL)
+               {
+                  ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
+                      png_ptr->read_buffer + prefix_size, &lzsize,
+                      text + prefix_size, newlength);
+
+                  if (ret == Z_STREAM_END)
+                  {
+                     if (new_size == *newlength)
+                     {
+                        if (terminate != 0)
+                           text[prefix_size + *newlength] = 0;
+
+                        if (prefix_size > 0)
+                           memcpy(text, png_ptr->read_buffer, prefix_size);
+
+                        {
+                           png_bytep old_ptr = png_ptr->read_buffer;
+
+                           png_ptr->read_buffer = text;
+                           png_ptr->read_buffer_size = buffer_size;
+                           text = old_ptr; /* freed below */
+                        }
+                     }
+
+                     else
+                     {
+                        /* The size changed on the second read, there can be no
+                         * guarantee that anything is correct at this point.
+                         * The 'msg' pointer has been set to "unexpected end of
+                         * LZ stream", which is fine, but return an error code
+                         * that the caller won't accept.
+                         */
+                        ret = PNG_UNEXPECTED_ZLIB_RETURN;
+                     }
+                  }
+
+                  else if (ret == Z_OK)
+                     ret = PNG_UNEXPECTED_ZLIB_RETURN; /* for safety */
+
+                  /* Free the text pointer (this is the old read_buffer on
+                   * success)
+                   */
+                  png_free(png_ptr, text);
+
+                  /* This really is very benign, but it's still an error because
+                   * the extra space may otherwise be used as a Trojan Horse.
+                   */
+                  if (ret == Z_STREAM_END &&
+                      chunklength - prefix_size != lzsize)
+                      png_chunk_benign_error(png_ptr, "extra compressed data");
+               }
+
+               else
+               {
+                  /* Out of memory allocating the buffer */
+                  ret = Z_MEM_ERROR;
+                  png_zstream_error(&png_ptr->zstream, Z_MEM_ERROR);
+               }
+            }
+
+            else
+            {
+               /* inflateReset failed, store the error message */
+               png_zstream_error(&png_ptr->zstream, ret);
+
+               if (ret == Z_STREAM_END)
+                  ret = PNG_UNEXPECTED_ZLIB_RETURN;
+            }
+         }
+
+         else if (ret == Z_OK)
+            ret = PNG_UNEXPECTED_ZLIB_RETURN;
+
+         /* Release the claimed stream */
+         png_ptr->zowner = 0;
+      }
+
+      else /* the claim failed */ if (ret == Z_STREAM_END) /* impossible! */
+         ret = PNG_UNEXPECTED_ZLIB_RETURN;
+
+      return ret;
+   }
+
+   else
+   {
+      /* Application/configuration limits exceeded */
+      png_zstream_error(&png_ptr->zstream, Z_MEM_ERROR);
+      return Z_MEM_ERROR;
+   }
+}
+#endif /* READ_COMPRESSED_TEXT */
+
+#ifdef PNG_READ_iCCP_SUPPORTED
+/* Perform a partial read and decompress, producing 'avail_out' bytes and
+ * reading from the current chunk as required.
+ */
+static int
+png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,
+    png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size,
+    int finish)
+{
+   if (png_ptr->zowner == png_ptr->chunk_name)
+   {
+      int ret;
+
+      /* next_in and avail_in must have been initialized by the caller. */
+      png_ptr->zstream.next_out = next_out;
+      png_ptr->zstream.avail_out = 0; /* set in the loop */
+
+      do
+      {
+         if (png_ptr->zstream.avail_in == 0)
+         {
+            if (read_size > *chunk_bytes)
+               read_size = (uInt)*chunk_bytes;
+            *chunk_bytes -= read_size;
+
+            if (read_size > 0)
+               png_crc_read(png_ptr, read_buffer, read_size);
+
+            png_ptr->zstream.next_in = read_buffer;
+            png_ptr->zstream.avail_in = read_size;
+         }
+
+         if (png_ptr->zstream.avail_out == 0)
+         {
+            uInt avail = ZLIB_IO_MAX;
+            if (avail > *out_size)
+               avail = (uInt)*out_size;
+            *out_size -= avail;
+
+            png_ptr->zstream.avail_out = avail;
+         }
+
+         /* Use Z_SYNC_FLUSH when there is no more chunk data to ensure that all
+          * the available output is produced; this allows reading of truncated
+          * streams.
+          */
+         ret = inflate(&png_ptr->zstream,
+             *chunk_bytes > 0 ? Z_NO_FLUSH : (finish ? Z_FINISH :
+             Z_SYNC_FLUSH));
+      }
+      while (ret == Z_OK && (*out_size > 0 || png_ptr->zstream.avail_out > 0));
+
+      *out_size += png_ptr->zstream.avail_out;
+      png_ptr->zstream.avail_out = 0; /* Should not be required, but is safe */
+
+      /* Ensure the error message pointer is always set: */
+      png_zstream_error(&png_ptr->zstream, ret);
+      return ret;
+   }
+
+   else
+   {
+      png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed");
+      return Z_STREAM_ERROR;
+   }
+}
+#endif /* READ_iCCP */
diff --git a/libpng-manual.txt b/libpng-manual.txt
index a9aa0fc..76d35d5 100644
--- a/libpng-manual.txt
+++ b/libpng-manual.txt
@@ -1,6 +1,6 @@
 libpng-manual.txt - A description on how to use and modify libpng
 
- libpng version 1.7.0beta85 - September 26, 2016
+ libpng version 1.7.0beta86 - December 27, 2016
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
@@ -11,7 +11,7 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.7.0beta85 - September 26, 2016
+ libpng versions 0.97, January 1998, through 1.7.0beta86 - December 27, 2016
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
 
@@ -5345,8 +5345,9 @@
 We prefer to use underscores in variable names rather than camelCase, except
 for a few type names that we inherit from zlib.h.
 
-We prefer "if (something != 0)" and "if (something == 0)"
-over "if (something)" and if "(!something)", respectively.
+We prefer "if (something != 0)" and "if (something == 0)" over
+"if (something)" and if "(!something)", respectively, and for pointers
+we prefer "if (some_pointer != NULL)" or "if (some_pointer == NULL)". 
 
 We do not use the TAB character for indentation in the C sources.
 
@@ -5360,7 +5361,7 @@
 an official declaration.
 
 This is your unofficial assurance that libpng from version 0.71 and
-upward through 1.7.0beta85 are Y2K compliant.  It is my belief that earlier
+upward through 1.7.0beta86 are Y2K compliant.  It is my belief that earlier
 versions were also Y2K compliant.
 
 Libpng only has two year fields.  One is a 2-byte unsigned integer
diff --git a/libpng.3 b/libpng.3
index 22eb58e..e8a186c 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,6 +1,6 @@
-.TH LIBPNG 3 "September 26, 2016"
+.TH LIBPNG 3 "December 27, 2016"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta85
+libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta86
 .SH SYNOPSIS
 \fB
 #include <png.h>\fP
@@ -500,7 +500,7 @@
 .SH LIBPNG.TXT
 libpng-manual.txt - A description on how to use and modify libpng
 
- libpng version 1.7.0beta85 - September 26, 2016
+ libpng version 1.7.0beta86 - December 27, 2016
  Updated and distributed by Glenn Randers-Pehrson
  <glennrp at users.sourceforge.net>
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
@@ -511,7 +511,7 @@
 
  Based on:
 
- libpng versions 0.97, January 1998, through 1.7.0beta85 - September 26, 2016
+ libpng versions 0.97, January 1998, through 1.7.0beta86 - December 27, 2016
  Updated and distributed by Glenn Randers-Pehrson
  Copyright (c) 1998-2015 Glenn Randers-Pehrson
 
@@ -5845,8 +5845,9 @@
 We prefer to use underscores in variable names rather than camelCase, except
 for a few type names that we inherit from zlib.h.
 
-We prefer "if (something != 0)" and "if (something == 0)"
-over "if (something)" and if "(!something)", respectively.
+We prefer "if (something != 0)" and "if (something == 0)" over
+"if (something)" and if "(!something)", respectively, and for pointers
+we prefer "if (some_pointer != NULL)" or "if (some_pointer == NULL)". 
 
 We do not use the TAB character for indentation in the C sources.
 
@@ -5860,7 +5861,7 @@
 an official declaration.
 
 This is your unofficial assurance that libpng from version 0.71 and
-upward through 1.7.0beta85 are Y2K compliant.  It is my belief that earlier
+upward through 1.7.0beta86 are Y2K compliant.  It is my belief that earlier
 versions were also Y2K compliant.
 
 Libpng only has two year fields.  One is a 2-byte unsigned integer
@@ -6020,7 +6021,7 @@
 
 Thanks to Frank J. T. Wojcik for helping with the documentation.
 
-Libpng version 1.7.0beta85 - September 26, 2016:
+Libpng version 1.7.0beta86 - December 27, 2016:
 Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
 Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
 
@@ -6045,7 +6046,7 @@
 
 This code is released under the libpng license.
 
-libpng versions 1.0.7, July 1, 2000, through 1.7.0beta85, September 26, 2016, are
+libpng versions 1.0.7, July 1, 2000, through 1.7.0beta86, December 27, 2016, are
 Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are
 derived from libpng-1.0.6, and are distributed according to the same
 disclaimer and license as libpng-1.0.6 with the following individuals
@@ -6144,7 +6145,7 @@
 
 Glenn Randers-Pehrson
 glennrp at users.sourceforge.net
-September 26, 2016
+December 27, 2016
 
 .\" end of man page
 
diff --git a/libpngpf.3 b/libpngpf.3
index 595daa3..e9b4783 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,6 +1,6 @@
-.TH LIBPNGPF 3 "September 26, 2016"
+.TH LIBPNGPF 3 "December 27, 2016"
 .SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta85
+libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta86
 (private functions)
 .SH SYNOPSIS
 \fB#include \fI"pngpriv.h"
diff --git a/png.5 b/png.5
index d95981c..5a24d99 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "September 26, 2016"
+.TH PNG 5 "December 27, 2016"
 .SH NAME
 png \- Portable Network Graphics (PNG) format
 .SH DESCRIPTION
diff --git a/png.c b/png.c
index 37ec214..5d34201 100644
--- a/png.c
+++ b/png.c
@@ -15,7 +15,7 @@
 #define PNG_SRC_FILE PNG_SRC_FILE_png
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef png_libpng_version_1_7_0beta85 Your_png_h_is_not_version_1_7_0beta85;
+typedef png_libpng_version_1_7_0beta86 Your_png_h_is_not_version_1_7_0beta86;
 
 /* Tells libpng that we have already handled the first "num_bytes" bytes
  * of the PNG file signature.  If the PNG data is embedded into another
@@ -704,14 +704,14 @@
 #else
 #  ifdef __STDC__
    return PNG_STRING_NEWLINE \
-     "libpng version 1.7.0beta85 - December 27, 2016" PNG_STRING_NEWLINE \
+     "libpng version 1.7.0beta86 - December 27, 2016" PNG_STRING_NEWLINE \
      "Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson" \
      PNG_STRING_NEWLINE \
      "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
      "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
      PNG_STRING_NEWLINE;
 #  else
-      return "libpng version 1.7.0beta85 - December 27, 2016\
+      return "libpng version 1.7.0beta86 - December 27, 2016\
       Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\
       Copyright (c) 1996-1997 Andreas Dilger\
       Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@@ -996,8 +996,13 @@
     * In 1.6.0 this test replaces the ones in pngrutil.c, in the gAMA chunk
     * handling code, which only required the value to be >0.
     */
-#  define ERRMSG (defined PNG_TRANSFORM_MECH_SUPPORTED) &&\
-                 (defined PNG_ERROR_TEXT_SUPPORTED)
+#  if (defined PNG_TRANSFORM_MECH_SUPPORTED) &&\
+      (defined PNG_ERROR_TEXT_SUPPORTED)
+#     define ERRMSG 1
+#  else
+#     define ERRMSG 0
+#  endif
+
 #  if ERRMSG
       png_const_charp errmsg;
 #  endif
diff --git a/png.h b/png.h
index ff41e62..7208e2b 100644
--- a/png.h
+++ b/png.h
@@ -1,7 +1,7 @@
 
 /* png.h - header file for PNG reference library
  *
- * libpng version 1.7.0beta85, September 26, 2016
+ * libpng version 1.7.0beta86, December 27, 2016
  *
  * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -12,7 +12,7 @@
  * Authors and maintainers:
  *   libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
  *   libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger
- *   libpng versions 0.97, January 1998, through 1.7.0beta85, September 26, 2016:
+ *   libpng versions 0.97, January 1998, through 1.7.0beta86, December 27, 2016:
  *     Glenn Randers-Pehrson.
  *   See also "Contributing Authors", below.
  */
@@ -25,7 +25,7 @@
  *
  * This code is released under the libpng license.
  *
- * libpng versions 1.0.7, July 1, 2000, through 1.7.0beta85, September 26, 2016, are
+ * libpng versions 1.0.7, July 1, 2000, through 1.7.0beta86, December 27, 2016, are
  * Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are
  * derived from libpng-1.0.6, and are distributed according to the same
  * disclaimer and license as libpng-1.0.6 with the following individuals
@@ -217,13 +217,13 @@
  * Y2K compliance in libpng:
  * =========================
  *
- *    September 26, 2016
+ *    December 27, 2016
  *
  *    Since the PNG Development group is an ad-hoc body, we can't make
  *    an official declaration.
  *
  *    This is your unofficial assurance that libpng from version 0.71 and
- *    upward through 1.7.0beta85 are Y2K compliant.  It is my belief that
+ *    upward through 1.7.0beta86 are Y2K compliant.  It is my belief that
  *    earlier versions were also Y2K compliant.
  *
  *    Libpng only has two year fields.  One is a 2-byte unsigned integer
@@ -285,8 +285,8 @@
  */
 
 /* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.7.0beta85"
-#define PNG_HEADER_VERSION_STRING " libpng version 1.7.0beta85 - September 26, 2016\n"
+#define PNG_LIBPNG_VER_STRING "1.7.0beta86"
+#define PNG_HEADER_VERSION_STRING " libpng version 1.7.0beta86 - December 27, 2016\n"
 
 #define PNG_LIBPNG_VER_SONUM   17
 #define PNG_LIBPNG_VER_DLLNUM  17
@@ -300,7 +300,7 @@
  * PNG_LIBPNG_VER_STRING, omitting any leading zero:
  */
 
-#define PNG_LIBPNG_VER_BUILD  85
+#define PNG_LIBPNG_VER_BUILD  86
 
 /* Release Status */
 #define PNG_LIBPNG_BUILD_ALPHA    1
@@ -560,7 +560,7 @@
 /* This triggers a compiler error in png.c, if png.c and png.h
  * do not agree upon the version number.
  */
-typedef char* png_libpng_version_1_7_0beta85;
+typedef char* png_libpng_version_1_7_0beta86;
 
 /* Basic control structions.  Read libpng-manual.txt or libpng.3 for more info.
  *
diff --git a/pngconf.h b/pngconf.h
index 87f882b..245e84f 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,7 +1,7 @@
 
 /* pngconf.h - machine configurable file for libpng
  *
- * libpng version 1.7.0beta85, September 26, 2016
+ * libpng version 1.7.0beta86, December 27, 2016
  *
  * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
diff --git a/pngpriv.h b/pngpriv.h
index b6ceb95..c0f2951 100644
--- a/pngpriv.h
+++ b/pngpriv.h
@@ -319,9 +319,13 @@
  * is just the affirm code; there's no reason to allow configuration of this
  * option.
  */
-#define PNG_AFFIRM_TEXT (PNG_RELEASE_BUILD ?\
-         (defined PNG_ERROR_TEXT_SUPPORTED) :\
-         (defined PNG_WARNINGS_SUPPORTED) || (defined PNG_CONSOLE_IO_SUPPORTED))
+#if PNG_RELEASE_BUILD ?\
+      (defined PNG_ERROR_TEXT_SUPPORTED) :\
+      (defined PNG_WARNINGS_SUPPORTED) || (defined PNG_CONSOLE_IO_SUPPORTED)
+#  define PNG_AFFIRM_TEXT 1
+#else
+#  define PNG_AFFIRM_TEXT 0
+#endif /* PNG_AFFIRM_TEXT definition */
 
 #define PNG_SRC_LINE (PNG_SRC_FILE + __LINE__)
 
diff --git a/pngtest.c b/pngtest.c
index 66c7cc7..46a70fd 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -2083,4 +2083,4 @@
 #endif
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef png_libpng_version_1_7_0beta85 Your_png_h_is_not_version_1_7_0beta85;
+typedef png_libpng_version_1_7_0beta86 Your_png_h_is_not_version_1_7_0beta86;
diff --git a/projects/vstudio/README.txt b/projects/vstudio/README.txt
index a299816..290ade1 100644
--- a/projects/vstudio/README.txt
+++ b/projects/vstudio/README.txt
@@ -1,7 +1,7 @@
 
 VisualStudio instructions
 
-libpng version 1.7.0beta85 - September 26, 2016
+libpng version 1.7.0beta86 - December 27, 2016
 
 Copyright (c) 2010,2013,2015 Glenn Randers-Pehrson
 
diff --git a/projects/vstudio/zlib.props b/projects/vstudio/zlib.props
index adf9c11..45a7f38 100644
--- a/projects/vstudio/zlib.props
+++ b/projects/vstudio/zlib.props
@@ -2,7 +2,7 @@
 <!--
  * zlib.props - location of zlib source
  *
- * libpng version 1.7.0beta85 - September 26, 2016
+ * libpng version 1.7.0beta86 - December 27, 2016
  *
  * Copyright (c) 2011,2013,2014 Glenn Randers-Pehrson
  *
diff --git a/scripts/README.txt b/scripts/README.txt
index 05b3a09..6d27a9f 100644
--- a/scripts/README.txt
+++ b/scripts/README.txt
@@ -1,9 +1,9 @@
 
-Makefiles for  libpng version 1.7.0beta85 - September 26, 2016
+Makefiles for  libpng version 1.7.0beta86 - December 27, 2016
 
 pnglibconf.h.prebuilt       =>  Stores configuration settings
  makefile.linux    =>  Linux/ELF makefile
-                       (gcc, creates libpng17.so.17.1.7.0beta85)
+                       (gcc, creates libpng17.so.17.1.7.0beta86)
  makefile.gcc      =>  Generic makefile (gcc, creates static libpng.a)
  makefile.knr      =>  Archaic UNIX Makefile that converts files with
                        ansi2knr (Requires ansi2knr.c from
@@ -33,12 +33,12 @@
  makefile.os2      =>  OS/2 Makefile (gcc and emx, requires libpng.def)
  makefile.sco      =>  For SCO OSr5  ELF and Unixware 7 with Native cc
  makefile.sggcc    =>  Silicon Graphics (gcc,
-                       creates libpng17.so.17.1.7.0beta85)
+                       creates libpng17.so.17.1.7.0beta86)
  makefile.sgi      =>  Silicon Graphics IRIX makefile (cc, creates static lib)
  makefile.solaris  =>  Solaris 2.X makefile (gcc,
-                       creates libpng17.so.17.1.7.0beta85)
+                       creates libpng17.so.17.1.7.0beta86)
  makefile.so9      =>  Solaris 9 makefile (gcc,
-                       creates libpng17.so.17.1.7.0beta85)
+                       creates libpng17.so.17.1.7.0beta86)
  makefile.std      =>  Generic UNIX makefile (cc, creates static libpng.a)
  makefile.sunos    =>  Sun makefile
  makefile.32sunu   =>  Sun Ultra 32-bit makefile
diff --git a/scripts/def.c b/scripts/def.c
index 2dca03e..8fa8347 100644
--- a/scripts/def.c
+++ b/scripts/def.c
@@ -21,7 +21,7 @@
 PNG_DFN "OS2 CODE PRELOAD MOVEABLE DISCARDABLE"
 PNG_DFN ""
 PNG_DFN "EXPORTS"
-PNG_DFN ";Version 1.7.0beta85"
+PNG_DFN ";Version 1.7.0beta86"
 
 #define PNG_EXPORTA(ordinal, type, name, args, attributes)\
         PNG_DFN "@" SYMBOL_PREFIX "@@" name "@"
diff --git a/scripts/libpng-config-head.in b/scripts/libpng-config-head.in
index 066c853..c13f265 100755
--- a/scripts/libpng-config-head.in
+++ b/scripts/libpng-config-head.in
@@ -11,7 +11,7 @@
 
 # Modeled after libxml-config.
 
-version=1.7.0beta85
+version=1.7.0beta86
 prefix=""
 libdir=""
 libs=""
diff --git a/scripts/libpng.pc.in b/scripts/libpng.pc.in
index 179535f..a05e6a2 100644
--- a/scripts/libpng.pc.in
+++ b/scripts/libpng.pc.in
@@ -5,6 +5,6 @@
 
 Name: libpng
 Description: Loads and saves PNG files
-Version: 1.7.0beta85
+Version: 1.7.0beta86
 Libs: -L${libdir} -lpng17
 Cflags: -I${includedir}
diff --git a/scripts/makefile.ne12bsd b/scripts/makefile.ne12bsd
index 14b8a25..3b088a1 100644
--- a/scripts/makefile.ne12bsd
+++ b/scripts/makefile.ne12bsd
@@ -17,7 +17,7 @@
 
 LIB=	png17
 SHLIB_MAJOR=	0
-SHLIB_MINOR=	1.7.0beta85
+SHLIB_MINOR=	1.7.0beta86
 SRCS=	png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
 	pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
 	pngwtran.c pngmem.c pngerror.c pngpread.c
diff --git a/scripts/makefile.netbsd b/scripts/makefile.netbsd
index 39de2b8..df2d897 100644
--- a/scripts/makefile.netbsd
+++ b/scripts/makefile.netbsd
@@ -17,7 +17,7 @@
 
 LIB=	png
 SHLIB_MAJOR=	17
-SHLIB_MINOR=	1.7.0beta85
+SHLIB_MINOR=	1.7.0beta86
 SRCS=	png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
 	pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
 	pngwtran.c pngmem.c pngerror.c pngpread.c
diff --git a/scripts/makefile.openbsd b/scripts/makefile.openbsd
index db1fd4e..fe99174 100644
--- a/scripts/makefile.openbsd
+++ b/scripts/makefile.openbsd
@@ -11,7 +11,7 @@
 MANDIR= ${PREFIX}/man/cat
 
 SHLIB_MAJOR=	17
-SHLIB_MINOR=	1.7.0beta85
+SHLIB_MINOR=	1.7.0beta86
 
 LIB=	png
 SRCS=	png.c pngerror.c pngget.c pngmem.c pngpread.c \
diff --git a/scripts/pnglibconf.h.prebuilt b/scripts/pnglibconf.h.prebuilt
index ca5faee..1ea9b03 100644
--- a/scripts/pnglibconf.h.prebuilt
+++ b/scripts/pnglibconf.h.prebuilt
@@ -1,8 +1,8 @@
-/* libpng 1.7.0beta85 STANDARD API DEFINITION */
+/* libpng 1.7.0beta86 STANDARD API DEFINITION */
 
 /* pnglibconf.h - library build configuration */
 
-/* libpng version 1.7.0beta85, September 26, 2016 */
+/* libpng version 1.7.0beta86, December 27, 2016 */
 
 /* Copyright (c) 1998-2016 Glenn Randers-Pehrson */
 
diff --git a/scripts/symbols.def b/scripts/symbols.def
index dede9d3..47c434c 100644
--- a/scripts/symbols.def
+++ b/scripts/symbols.def
@@ -1,4 +1,4 @@
-;Version 1.7.0beta85
+;Version 1.7.0beta86
 ;--------------------------------------------------------------
 ; LIBPNG symbol list as a Win32 DEF file
 ; Contains all the symbols that can be exported from libpng