Imported from libpng-1.2.0beta1.tar
diff --git a/pngtest.c b/pngtest.c
index daaa6b8..09590fe 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1,7 +1,7 @@
 
 /* pngtest.c - a simple test program to test libpng
  *
- * libpng 1.0.12beta1 - May 14, 2001
+ * libpng 1.2.0beta1 - May 6, 2001
  * For conditions of distribution and use, see copyright notice in png.h
  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -51,20 +51,16 @@
 #endif
 
 #if defined(PNG_NO_STDIO)
-#  if defined(_WIN32_WCE)
-     typedef HANDLE                png_FILE_p;
-#  else
-     typedef FILE                * png_FILE_p;
-#  endif
+#if defined(_WIN32_WCE)
+typedef HANDLE                png_FILE_p;
+#else
+typedef FILE                * png_FILE_p;
+#endif
 #endif
 
 /* Makes pngtest verbose so we can find problems (needs to be before png.h) */
 #ifndef PNG_DEBUG
-#  define PNG_DEBUG 0
-#endif
-
-#if !PNG_DEBUG
-#  define SINGLE_ROWBUF_ALLOC	/* makes buffer overruns easier to nail */
+#define PNG_DEBUG 0
 #endif
 
 /* Turn on CPU timing
@@ -283,7 +279,7 @@
 
    if (check != length)
    {
-      png_error(png_ptr, "Read Error!");
+      png_error(png_ptr, "Read Error");
    }
 }
 #else
@@ -488,15 +484,14 @@
    /* This calls the library allocator twice, once to get the requested
       buffer and once to get a new free list entry. */
    {
-      memory_infop pinfo = (memory_infop)png_malloc_default(png_ptr,
-         sizeof *pinfo);
+      memory_infop pinfo = png_malloc_default(png_ptr, sizeof *pinfo);
       pinfo->size = size;
       current_allocation += size;
       total_allocation += size;
       num_allocations ++;
       if (current_allocation > maximum_allocation)
          maximum_allocation = current_allocation;
-      pinfo->pointer = (png_voidp)png_malloc_default(png_ptr, size);
+      pinfo->pointer = png_malloc_default(png_ptr, size);
       pinfo->next = pinformation;
       pinformation = pinfo;
       /* Make sure the caller isn't assuming zeroed memory. */
@@ -538,7 +533,7 @@
                fprintf(STDERR, "Duplicate free of memory\n");
             /* We must free the list element too, but first kill
                the memory that is to be freed. */
-            png_memset(ptr, 0x55, pinfo->size);
+            memset(ptr, 0x55, pinfo->size);
             png_free_default(png_ptr, pinfo);
             pinfo=NULL;
             break;
@@ -569,17 +564,8 @@
 {
    static png_FILE_p fpin;
    static png_FILE_p fpout;  /* "static" prevents setjmp corruption */
-   png_structp read_ptr;
-   png_infop read_info_ptr, end_info_ptr;
-#ifdef PNG_WRITE_SUPPORTED
-   png_structp write_ptr;
-   png_infop write_info_ptr;
-   png_infop write_end_info_ptr;
-#else
-   png_structp write_ptr = NULL;
-   png_infop write_info_ptr = NULL;
-   png_infop write_end_info_ptr = NULL;
-#endif
+   png_structp read_ptr, write_ptr;
+   png_infop read_info_ptr, write_info_ptr, end_info_ptr, write_end_info_ptr;
    png_bytep row_buf;
    png_uint_32 y;
    png_uint_32 width, height;
@@ -634,7 +620,6 @@
    png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error,
        pngtest_warning);
 #endif
-#ifdef PNG_WRITE_SUPPORTED
 #ifdef PNG_USER_MEM_SUPPORTED
    write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
       (png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL,
@@ -647,13 +632,12 @@
    png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error,
        pngtest_warning);
 #endif
-#endif
    png_debug(0, "Allocating read_info, write_info and end_info structures\n");
    read_info_ptr = png_create_info_struct(read_ptr);
-   end_info_ptr = png_create_info_struct(read_ptr);
-#ifdef PNG_WRITE_SUPPORTED
    write_info_ptr = png_create_info_struct(write_ptr);
+   end_info_ptr = png_create_info_struct(read_ptr);
    write_end_info_ptr = png_create_info_struct(write_ptr);
+#ifdef PNG_USER_MEM_SUPPORTED
 #endif
 
 #ifdef PNG_SETJMP_SUPPORTED
@@ -666,10 +650,8 @@
    {
       fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
       png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
-#ifdef PNG_WRITE_SUPPORTED
       png_destroy_info_struct(write_ptr, &write_end_info_ptr);
       png_destroy_write_struct(&write_ptr, &write_info_ptr);
-#endif
       FCLOSE(fpin);
       FCLOSE(fpout);
       return (1);
@@ -678,7 +660,6 @@
    png_memcpy(png_jmpbuf(read_ptr),jmpbuf,sizeof(jmp_buf));
 #endif
 
-#ifdef PNG_WRITE_SUPPORTED
    png_debug(0, "Setting jmpbuf for write struct\n");
 #ifdef USE_FAR_KEYWORD
    if (setjmp(jmpbuf))
@@ -689,9 +670,7 @@
       fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
       png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
       png_destroy_info_struct(write_ptr, &write_end_info_ptr);
-#ifdef PNG_WRITE_SUPPORTED
       png_destroy_write_struct(&write_ptr, &write_info_ptr);
-#endif
       FCLOSE(fpin);
       FCLOSE(fpout);
       return (1);
@@ -700,37 +679,28 @@
    png_memcpy(png_jmpbuf(write_ptr),jmpbuf,sizeof(jmp_buf));
 #endif
 #endif
-#endif
 
    png_debug(0, "Initializing input and output streams\n");
 #if !defined(PNG_NO_STDIO)
    png_init_io(read_ptr, fpin);
-#  ifdef PNG_WRITE_SUPPORTED
    png_init_io(write_ptr, fpout);
-#  endif
 #else
    png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data);
-#  ifdef PNG_WRITE_SUPPORTED
    png_set_write_fn(write_ptr, (png_voidp)fpout,  pngtest_write_data,
-#    if defined(PNG_WRITE_FLUSH_SUPPORTED)
+#if defined(PNG_WRITE_FLUSH_SUPPORTED)
       pngtest_flush);
-#    else
+#else
       NULL);
-#    endif
-#  endif
+#endif
 #endif
    if(status_dots_requested == 1)
    {
-#ifdef PNG_WRITE_SUPPORTED
       png_set_write_status_fn(write_ptr, write_row_callback);
-#endif
       png_set_read_status_fn(read_ptr, read_row_callback);
    }
    else
    {
-#ifdef PNG_WRITE_SUPPORTED
       png_set_write_status_fn(write_ptr, NULL);
-#endif
       png_set_read_status_fn(read_ptr, NULL);
    }
 
@@ -1014,29 +984,32 @@
    }
 #endif
 
-#ifdef PNG_WRITE_SUPPORTED
    png_debug(0, "\nWriting info struct\n");
 
 /* If we wanted, we could write info in two steps:
    png_write_info_before_PLTE(write_ptr, write_info_ptr);
  */
    png_write_info(write_ptr, write_info_ptr);
-#endif
 
-#ifdef SINGLE_ROWBUF_ALLOC
-   png_debug(0, "\nAllocating row buffer...");
+   png_debug(0, "\nAllocating row buffer \n");
    row_buf = (png_bytep)png_malloc(read_ptr,
       png_get_rowbytes(read_ptr, read_info_ptr));
-   png_debug1(0, "0x%08lx\n\n", (unsigned long)row_buf);
-#endif /* SINGLE_ROWBUF_ALLOC */
+   if (row_buf == NULL)
+   {
+      fprintf(STDERR, "No memory to allocate row buffer\n");
+      png_destroy_read_struct(&read_ptr, &read_info_ptr, (png_infopp)NULL);
+      png_destroy_info_struct(write_ptr, &write_end_info_ptr);
+      png_destroy_write_struct(&write_ptr, &write_info_ptr);
+      FCLOSE(fpin);
+      FCLOSE(fpout);
+      return (1);
+   }
    png_debug(0, "Writing row data\n");
 
 #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
   defined(PNG_WRITE_INTERLACING_SUPPORTED)
    num_pass = png_set_interlace_handling(read_ptr);
-#  ifdef PNG_WRITE_SUPPORTED
    png_set_interlace_handling(write_ptr);
-#  endif
 #else
    num_pass=1;
 #endif
@@ -1051,16 +1024,7 @@
       png_debug1(0, "Writing row data for pass %d\n",pass);
       for (y = 0; y < height; y++)
       {
-#ifndef SINGLE_ROWBUF_ALLOC
-         png_debug2(0, "\nAllocating row buffer (pass %d, y = %ld)...", pass,y);
-         row_buf = (png_bytep)png_malloc(read_ptr,
-            png_get_rowbytes(read_ptr, read_info_ptr));
-         png_debug2(0, "0x%08lx (%ld bytes)\n", (unsigned long)row_buf,
-            png_get_rowbytes(read_ptr, read_info_ptr));
-#endif /* !SINGLE_ROWBUF_ALLOC */
          png_read_rows(read_ptr, (png_bytepp)&row_buf, (png_bytepp)NULL, 1);
-
-#ifdef PNG_WRITE_SUPPORTED
 #ifdef PNGTEST_TIMING
          t_stop = (float)clock();
          t_decode += (t_stop - t_start);
@@ -1072,12 +1036,6 @@
          t_encode += (t_stop - t_start);
          t_start = t_stop;
 #endif
-#endif /* PNG_WRITE_SUPPORTED */
-
-#ifndef SINGLE_ROWBUF_ALLOC
-         png_debug2(0, "Freeing row buffer (pass %d, y = %ld)\n\n", pass, y);
-         png_free(read_ptr, row_buf);
-#endif /* !SINGLE_ROWBUF_ALLOC */
       }
    }
 
@@ -1140,9 +1098,7 @@
       }
    }
 #endif
-#ifdef PNG_WRITE_SUPPORTED
    png_write_end(write_ptr, write_end_info_ptr);
-#endif
 
 #ifdef PNG_EASY_ACCESS_SUPPORTED
    if(verbose)
@@ -1156,20 +1112,11 @@
 #endif
 
    png_debug(0, "Destroying data structs\n");
-#ifdef SINGLE_ROWBUF_ALLOC
-   png_debug(1, "destroying row_buf for read_ptr\n");
    png_free(read_ptr, row_buf);
    row_buf=NULL;
-#endif /* SINGLE_ROWBUF_ALLOC */
-   png_debug(1, "destroying read_ptr, read_info_ptr, end_info_ptr\n");
    png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
-#ifdef PNG_WRITE_SUPPORTED
-   png_debug(1, "destroying write_end_info_ptr\n");
    png_destroy_info_struct(write_ptr, &write_end_info_ptr);
-   png_debug(1, "destroying write_ptr, write_info_ptr\n");
    png_destroy_write_struct(&write_ptr, &write_info_ptr);
-#endif
-   png_debug(0, "Destruction complete.\n");
 
    FCLOSE(fpin);
    FCLOSE(fpout);
@@ -1511,4 +1458,4 @@
 }
 
 /* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_0_12beta1 your_png_h_is_not_version_1_0_12beta1;
+typedef version_1_2_0beta1 your_png_h_is_not_version_1_2_0beta1;