DO NOT MERGE Update libpng to 1.6.20

BUG:23265085
Change-Id: I85199805636d771f3597b691b63bc0bf46084833
(cherry picked from commit bbe98b40cda082024b669fa508931042eed18f82)

buffer_write(struct display *dp, struct buffer *buffer, png_bytep data,
 png_size_t size)
 /* Generic write function used both from the write callback provided to
    * libpng and from the generic read code.
    */
{
 /* Write the data into the buffer, adding buffers as required */
 struct buffer_list *last = buffer->last;
 size_t end_count = buffer->end_count;

 while (size > 0)
 {
 size_t avail;

 if (end_count >= sizeof last->buffer)
 {
 if (last->next == NULL)
 {
            last = buffer_extend(last);

 if (last == NULL)
               display_log(dp, APP_ERROR, "out of memory saving file");
 }

 else
            last = last->next;

         buffer->last = last; /* avoid the need to rewrite every time */
         end_count = 0;
 }

      avail = (sizeof last->buffer) - end_count;
 if (avail > size)
         avail = size;

      memcpy(last->buffer + end_count, data, avail);
      end_count += avail;
      size -= avail;
      data += avail;
 }

   buffer->end_count = end_count;
}

buffer_write(struct display *dp, struct buffer *buffer, png_bytep data,
 png_size_t size)
 /* Generic write function used both from the write callback provided to
    * libpng and from the generic read code.
    */
{
 /* Write the data into the buffer, adding buffers as required */
 struct buffer_list *last = buffer->last;
 size_t end_count = buffer->end_count;

 while (size > 0)
 {
 size_t avail;

 if (end_count >= sizeof last->buffer)
 {
 if (last->next == NULL)
 {
            last = buffer_extend(last);

 if (last == NULL)
               display_log(dp, APP_ERROR, "out of memory saving file");
 }

 else
            last = last->next;

         buffer->last = last; /* avoid the need to rewrite every time */
         end_count = 0;
 }

      avail = (sizeof last->buffer) - end_count;
 if (avail > size)
         avail = size;

      memcpy(last->buffer + end_count, data, avail);
      end_count += avail;
      size -= avail;
      data += avail;
 }

   buffer->end_count = end_count;
}
