contrib: Apply various fixes to libtests

pngimage.c:
Initialize sig_bits on a NOTREACHED path to avoid warnings about using
uninitialized variables.

pngstest.c:
Enlarge buffers and fix signedness to avoid legitimate warnings about
potential buffer overflows.

pngunknown.c:
pngvalid.c:
Use NULL instead of 0 for pointers and apply other style fixes.

makepng.c:
tarith.c:
Apply various style fixes.

Also remove the "last changed" version info from source comments.
The version control system maintains this information automatically.
This commit is contained in:
Cosmin Truta 2021-03-12 22:54:32 -05:00
parent d6e13b2acd
commit e2bb5e7512
9 changed files with 360 additions and 273 deletions

View File

@ -2,8 +2,6 @@
#
# Copyright (c) 2013 John Cunningham Bowler
#
# Last changed in libpng 1.6.0 [February 14, 2013]
#
# This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer
# and license in png.h

View File

@ -3,8 +3,6 @@
/* Copyright: */
#define COPYRIGHT "\251 2013,2015 John Cunningham Bowler"
/*
* Last changed in libpng 1.6.20 [November 24, 2015]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
@ -299,7 +297,9 @@ generate_palette(png_colorp palette, png_bytep trans, int bit_depth,
unsigned int x, y;
volatile unsigned int ip = 0;
for (x=0; x<size; ++x) for (y=0; y<size; ++y)
for (x=0; x<size; ++x)
{
for (y=0; y<size; ++y)
{
ip = x + (size * y);
@ -319,6 +319,7 @@ generate_palette(png_colorp palette, png_bytep trans, int bit_depth,
xyinterp(x, y, 0, 102, 204, 255),
gamma_table);
}
}
return ip+1;
}
@ -396,7 +397,7 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
image_size_of_type(color_type, bit_depth, colors, small)-1;
png_uint_32 depth_max = (1U << bit_depth)-1; /* up to 65536 */
if (colors[0] == 0) if (small)
if (colors[0] == 0 && small)
{
unsigned int pixel_depth = pixel_depth_of_type(color_type, bit_depth);
@ -858,11 +859,14 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
{
unsigned int i;
if (real_gamma == 45455) for (i=0; i<256; ++i)
if (real_gamma == 45455)
{
for (i=0; i<256; ++i)
{
gamma_table[i] = (png_byte)i;
conv = 1.;
}
}
else
{
@ -1430,12 +1434,15 @@ find_parameters(png_const_charp what, png_charp param, png_charp *list,
for (i=0; *param && i<nparams; ++i)
{
list[i] = param;
while (*++param) if (*param == '\n' || *param == ':')
while (*++param)
{
if (*param == '\n' || *param == ':')
{
*param++ = 0; /* Terminate last parameter */
break; /* And start a new one. */
}
}
}
if (*param)
{

View File

@ -1,9 +1,9 @@
/* pngimage.c
*
* Copyright (c) 2021 Cosmin Truta
* Copyright (c) 2015,2016 John Cunningham Bowler
*
* Last changed in libpng 1.6.24 [August 4, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
@ -12,6 +12,7 @@
* using png_read_png and then write with png_write_png. Test all possible
* transforms.
*/
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
@ -317,11 +318,10 @@ transform_name(int t)
t &= -t; /* first set bit */
for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)
{
for (i=0; i<TTABLE_SIZE; ++i)
if (transform_info[i].name != NULL)
if ((transform_info[i].transform & t) != 0)
return transform_info[i].name;
}
return "invalid transform";
}
@ -338,7 +338,9 @@ validate_T(void)
{
unsigned int i;
for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)
for (i=0; i<TTABLE_SIZE; ++i)
{
if (transform_info[i].name != NULL)
{
if (transform_info[i].when & TRANSFORM_R)
read_transforms |= transform_info[i].transform;
@ -346,6 +348,7 @@ validate_T(void)
if (transform_info[i].when & TRANSFORM_W)
write_transforms |= transform_info[i].transform;
}
}
/* Reversible transforms are those which are supported on both read and
* write.
@ -962,7 +965,9 @@ update_display(struct display *dp)
int bd = dp->bit_depth;
unsigned int i;
for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)
for (i=0; i<TTABLE_SIZE; ++i)
{
if (transform_info[i].name != NULL)
{
int transform = transform_info[i].transform;
@ -978,6 +983,7 @@ update_display(struct display *dp)
else if ((transform_info[i].when & TRANSFORM_R) != 0)
inactive |= transform;
}
}
/* Some transforms appear multiple times in the table; the 'active' status
* is the logical OR of these and the inactive status must be adjusted to
@ -1081,7 +1087,8 @@ compare_read(struct display *dp, int applied_transforms)
size_t x;
/* Find the first error */
for (x=0; x<rowbytes-1; ++x) if (row[x] != orig[x])
for (x=0; x<rowbytes-1; ++x)
if (row[x] != orig[x])
break;
display_log(dp, APP_FAIL,
@ -1137,6 +1144,7 @@ compare_read(struct display *dp, int applied_transforms)
display_log(dp, LIBPNG_ERROR, "invalid colour type %d",
color_type);
/*NOTREACHED*/
memset(sig_bits, 0, sizeof(sig_bits));
bpp = 0;
break;
}
@ -1198,7 +1206,7 @@ compare_read(struct display *dp, int applied_transforms)
sig_bits[0] = (png_byte)b;
break;
case 4: /* Relicate twice */
case 4: /* Replicate twice */
/* Value is 1, 2, 3 or 4 */
b = 0xf & ((0xf << 4) >> sig_bits[0]);
b |= b << 4;
@ -1686,7 +1694,8 @@ main(int argc, char **argv)
printf("%s: pngimage ", pass ? "PASS" : "FAIL");
for (j=1; j<option_end; ++j) if (j != ilog)
for (j=1; j<option_end; ++j)
if (j != ilog)
printf("%s ", argv[j]);
printf("%s\n", d.filename);

View File

@ -1,7 +1,7 @@
/*-
* pngstest.c
/* pngstest.c
*
* Last changed in libpng 1.6.31 [July 27, 2017]
* Copyright (c) 2021 Cosmin Truta
* Copyright (c) 2013-2017 John Cunningham Bowler
*
* This code is released under the libpng license.
@ -10,8 +10,9 @@
*
* Test for the PNG 'simplified' APIs.
*/
#define _ISOC90_SOURCE 1
#define MALLOC_CHECK_ 2/*glibc facility: turn on debugging*/
#define MALLOC_CHECK_ 2 /*glibc facility: turn on debugging*/
#include <stddef.h>
#include <stdlib.h>
@ -2701,7 +2702,7 @@ compare_two_images(Image *a, Image *b, int via_linear,
{
if ((a->opts & ACCUMULATE) == 0)
{
char pindex[9];
char pindex[16];
sprintf(pindex, "%lu[%lu]", (unsigned long)y,
(unsigned long)a->image.colormap_entries);
logerror(a, a->file_name, ": bad pixel index: ", pindex);
@ -2713,7 +2714,7 @@ compare_two_images(Image *a, Image *b, int via_linear,
{
if ((b->opts & ACCUMULATE) == 0)
{
char pindex[9];
char pindex[16];
sprintf(pindex, "%lu[%lu]", (unsigned long)y,
(unsigned long)b->image.colormap_entries);
logerror(b, b->file_name, ": bad pixel index: ", pindex);
@ -2820,8 +2821,11 @@ compare_two_images(Image *a, Image *b, int via_linear,
bchannels = component_loc(bloc, formatb);
/* Hence the btoa array. */
for (i=0; i<4; ++i) if (bloc[i] < 4)
for (i=0; i<4; ++i)
{
if (bloc[i] < 4)
btoa[bloc[i]] = aloc[i]; /* may be '4' for alpha */
}
if (alpha_added)
alpha_added = bloc[0]; /* location of alpha channel in image b */
@ -3209,10 +3213,10 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
else if (image->opts & USE_FILE)
{
#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
static int counter = 0;
static unsigned int counter = 0;
char name[32];
sprintf(name, "%s%d.png", tmpf, ++counter);
sprintf(name, "%s%u.png", tmpf, ++counter);
if (png_image_write_to_file(&image->image, name, convert_to_8bit,
image->buffer+16, (png_int_32)image->stride, image->colormap))

View File

@ -1,7 +1,7 @@
/* pngunknown.c - test the read side unknown chunk handling
*
* Last changed in libpng 1.6.32 [August 24, 2017]
* Copyright (c) 2021 Cosmin Truta
* Copyright (c) 2015,2017 Glenn Randers-Pehrson
* Written by John Cunningham Bowler
*
@ -370,7 +370,9 @@ find_by_flag(png_uint_32 flag)
{
int i = NINFO;
while (--i >= 0) if (chunk_info[i].flag == flag) return i;
while (--i >= 0)
if (chunk_info[i].flag == flag)
return i;
fprintf(stderr, "pngunknown: internal error\n");
exit(4);
@ -547,19 +549,21 @@ read_callback(png_structp pp, png_unknown_chunkp pc)
case PNG_HANDLE_CHUNK_AS_DEFAULT:
case PNG_HANDLE_CHUNK_NEVER:
discard = 1/*handled; discard*/;
discard = 1; /*handled; discard*/
break;
case PNG_HANDLE_CHUNK_IF_SAFE:
case PNG_HANDLE_CHUNK_ALWAYS:
discard = 0/*not handled; keep*/;
discard = 0; /*not handled; keep*/
break;
}
/* Also store information about this chunk in the display, the relevant flag
* is set if the chunk is to be kept ('not handled'.)
*/
if (chunk >= 0) if (!discard) /* stupidity to stop a GCC warning */
if (chunk >= 0)
{
if (!discard) /* stupidity to stop a GCC warning */
{
png_uint_32 flag = chunk_info[chunk].flag;
@ -569,6 +573,7 @@ read_callback(png_structp pp, png_unknown_chunkp pc)
else
d->before_IDAT |= flag;
}
}
/* However if there is no support to store unknown chunks don't ask libpng to
* do it; there will be an png_error.
@ -841,7 +846,8 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
{
png_uint_32 y;
for (y=0; y<height; ++y) if (PNG_ROW_IN_INTERLACE_PASS(y, ipass))
for (y=0; y<height; ++y)
if (PNG_ROW_IN_INTERLACE_PASS(y, ipass))
png_read_row(d->png_ptr, NULL, NULL);
}
}
@ -1091,15 +1097,15 @@ perform_one_test_safe(FILE *fp, int argc, const char **argv,
static const char *standard_tests[] =
{
"discard", "default=discard", 0,
"save", "default=save", 0,
"if-safe", "default=if-safe", 0,
"vpAg", "vpAg=if-safe", 0,
"sTER", "sTER=if-safe", 0,
"IDAT", "default=discard", "IDAT=save", 0,
"discard", "default=discard", NULL,
"save", "default=save", NULL,
"if-safe", "default=if-safe", NULL,
"vpAg", "vpAg=if-safe", NULL,
"sTER", "sTER=if-safe", NULL,
"IDAT", "default=discard", "IDAT=save", NULL,
"sAPI", "bKGD=save", "cHRM=save", "gAMA=save", "all=discard", "iCCP=save",
"sBIT=save", "sRGB=save", "eXIf=save", 0,
0/*end*/
"sBIT=save", "sRGB=save", "eXIf=save", NULL,
NULL /*end*/
};
static PNG_NORETURN void
@ -1115,7 +1121,7 @@ int
main(int argc, const char **argv)
{
FILE *fp;
png_uint_32 default_flags[4/*valid,unknown{before,after}*/];
png_uint_32 default_flags[4]; /*valid,unknown{before,after}*/
int strict = 0, default_tests = 0;
const char *count_argv = "default=save";
const char *touch_file = NULL;
@ -1153,7 +1159,8 @@ main(int argc, const char **argv)
/* GCC BUG: if (default_tests && argc != 1) triggers some weird GCC argc
* optimization which causes warnings with -Wstrict-overflow!
*/
else if (default_tests) if (argc != 1)
else if (default_tests)
if (argc != 1)
usage(d.program, "extra arguments");
/* The name of the test file is the last argument; remove it. */
@ -1216,7 +1223,11 @@ main(int argc, const char **argv)
const char *result;
int arg_count = 0;
while (*next) ++next, ++arg_count;
while (*next != NULL)
{
++next;
++arg_count;
}
perform_one_test_safe(fp, arg_count, test, default_flags, &d,
this_test);

View File

@ -1,7 +1,7 @@
/* pngvalid.c - validate libpng by constructing then reading png files.
*
* Last changed in libpng 1.6.31 [July 27, 2017]
* Copyright (c) 2021 Cosmin Truta
* Copyright (c) 2014-2017 John Cunningham Bowler
*
* This code is released under the libpng license.
@ -5823,8 +5823,9 @@ test_standard(png_modifier* const pm, png_byte const colour_type,
for (interlace_type = PNG_INTERLACE_NONE;
interlace_type < INTERLACE_LAST; ++interlace_type)
{
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
interlace_type, 0, 0, 0), do_read_interlace, pm->use_update_info);
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, interlace_type, 0, 0, 0), do_read_interlace,
pm->use_update_info);
if (fail(pm))
return 0;
@ -5877,22 +5878,24 @@ test_size(png_modifier* const pm, png_byte const colour_type,
{
png_uint_32 h, w;
for (h=1; h<=16; h+=hinc[bdlo]) for (w=1; w<=16; w+=winc[bdlo])
for (h=1; h<=16; h+=hinc[bdlo])
{
for (w=1; w<=16; w+=winc[bdlo])
{
/* First test all the 'size' images against the sequential
* reader using libpng to deinterlace (where required.) This
* validates the write side of libpng. There are four possibilities
* to validate.
*/
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_NONE, w, h, 0), 0/*do_interlace*/,
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_NONE, w, h, 0), 0/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
return 0;
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_NONE, w, h, 1), 0/*do_interlace*/,
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_NONE, w, h, 1), 0/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
@ -5902,8 +5905,8 @@ test_size(png_modifier* const pm, png_byte const colour_type,
* in the progressive case this does actually make a difference
* to the code used in the non-interlaced case too.
*/
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_NONE, w, h, 0), 1/*do_interlace*/,
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_NONE, w, h, 0), 1/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
@ -5911,8 +5914,8 @@ test_size(png_modifier* const pm, png_byte const colour_type,
# if CAN_WRITE_INTERLACE
/* Validate the pngvalid code itself: */
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_ADAM7, w, h, 1), 1/*do_interlace*/,
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_ADAM7, w, h, 1), 1/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
@ -5920,6 +5923,7 @@ test_size(png_modifier* const pm, png_byte const colour_type,
# endif
}
}
}
/* Now do the tests of libpng interlace handling, after we have made sure
* that the pngvalid version works:
@ -5928,17 +5932,19 @@ test_size(png_modifier* const pm, png_byte const colour_type,
{
png_uint_32 h, w;
for (h=1; h<=16; h+=hinc[bdlo]) for (w=1; w<=16; w+=winc[bdlo])
for (h=1; h<=16; h+=hinc[bdlo])
{
for (w=1; w<=16; w+=winc[bdlo])
{
# ifdef PNG_READ_INTERLACING_SUPPORTED
/* Test with pngvalid generated interlaced images first; we have
* already verify these are ok (unless pngvalid has self-consistent
* read/write errors, which is unlikely), so this detects errors in the
* read side first:
* read/write errors, which is unlikely), so this detects errors in
* the read side first:
*/
# if CAN_WRITE_INTERLACE
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_ADAM7, w, h, 1), 0/*do_interlace*/,
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_ADAM7, w, h, 1), 0/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
@ -5948,8 +5954,8 @@ test_size(png_modifier* const pm, png_byte const colour_type,
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Test the libpng write side against the pngvalid read side: */
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_ADAM7, w, h, 0), 1/*do_interlace*/,
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_ADAM7, w, h, 0), 1/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
@ -5959,8 +5965,8 @@ test_size(png_modifier* const pm, png_byte const colour_type,
# ifdef PNG_READ_INTERLACING_SUPPORTED
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Test both together: */
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
PNG_INTERLACE_ADAM7, w, h, 0), 0/*do_interlace*/,
standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo),
0/*palette*/, PNG_INTERLACE_ADAM7, w, h, 0), 0/*do_interlace*/,
pm->use_update_info);
if (fail(pm))
@ -5969,6 +5975,7 @@ test_size(png_modifier* const pm, png_byte const colour_type,
# endif /* READ_INTERLACING */
}
}
}
return 1; /* keep going */
}
@ -10650,17 +10657,22 @@ static void perform_gamma_transform_tests(png_modifier *pm)
{
unsigned int i, j;
for (i=0; i<pm->ngamma_tests; ++i) for (j=0; j<pm->ngamma_tests; ++j)
for (i=0; i<pm->ngamma_tests; ++i)
{
for (j=0; j<pm->ngamma_tests; ++j)
{
if (i != j)
{
gamma_transform_test(pm, colour_type, bit_depth, palette_number,
pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], 0/*sBIT*/,
pm->use_input_precision, 0 /*do not scale16*/);
pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
0/*sBIT*/, pm->use_input_precision, 0/*do not scale16*/);
if (fail(pm))
return;
}
}
}
}
}
static void perform_gamma_sbit_tests(png_modifier *pm)
@ -10688,7 +10700,9 @@ static void perform_gamma_sbit_tests(png_modifier *pm)
{
unsigned int j;
for (j=0; j<pm->ngamma_tests; ++j) if (i != j)
for (j=0; j<pm->ngamma_tests; ++j)
{
if (i != j)
{
gamma_transform_test(pm, colour_type, bit_depth, npalette,
pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
@ -10700,6 +10714,7 @@ static void perform_gamma_sbit_tests(png_modifier *pm)
}
}
}
}
}
/* Note that this requires a 16 bit source image but produces 8 bit output, so
@ -10947,7 +10962,9 @@ perform_gamma_composition_tests(png_modifier *pm, int do_background,
unsigned int i, j;
/* Don't skip the i==j case here - it's relevant. */
for (i=0; i<pm->ngamma_tests; ++i) for (j=0; j<pm->ngamma_tests; ++j)
for (i=0; i<pm->ngamma_tests; ++i)
{
for (j=0; j<pm->ngamma_tests; ++j)
{
gamma_composition_test(pm, colour_type, bit_depth, palette_number,
pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
@ -10957,6 +10974,7 @@ perform_gamma_composition_tests(png_modifier *pm, int do_background,
return;
}
}
}
}
#endif /* READ_BACKGROUND || READ_ALPHA_MODE */
@ -11057,7 +11075,7 @@ perform_gamma_test(png_modifier *pm, int summary)
pm->calculations_use_input_precision = 0;
if (summary)
summarize_gamma_errors(pm, 0/*who*/, 1/*low bit depth*/, 1/*indexed*/);
summarize_gamma_errors(pm, NULL/*who*/, 1/*low bit depth*/, 1/*indexed*/);
if (fail(pm))
return;
@ -11183,7 +11201,9 @@ png_pass_start_row(int pass)
{
int x, y;
++pass;
for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass)
for (y=0; y<8; ++y)
for (x=0; x<8; ++x)
if (adam7[y][x] == pass)
return y;
return 0xf;
}
@ -11193,7 +11213,9 @@ png_pass_start_col(int pass)
{
int x, y;
++pass;
for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass)
for (x=0; x<8; ++x)
for (y=0; y<8; ++y)
if (adam7[y][x] == pass)
return x;
return 0xf;
}
@ -11203,7 +11225,11 @@ png_pass_row_shift(int pass)
{
int x, y, base=(-1), inc=8;
++pass;
for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass)
for (y=0; y<8; ++y)
{
for (x=0; x<8; ++x)
{
if (adam7[y][x] == pass)
{
if (base == (-1))
base = y;
@ -11216,6 +11242,8 @@ png_pass_row_shift(int pass)
else if (inc != y-base)
return 0xff; /* error - more than one 'inc' value! */
}
}
}
if (base == (-1)) return 0xfe; /* error - no row in pass! */
@ -11237,7 +11265,11 @@ png_pass_col_shift(int pass)
{
int x, y, base=(-1), inc=8;
++pass;
for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass)
for (x=0; x<8; ++x)
{
for (y=0; y<8; ++y)
{
if (adam7[y][x] == pass)
{
if (base == (-1))
base = x;
@ -11250,6 +11282,8 @@ png_pass_col_shift(int pass)
else if (inc != x-base)
return 0xff; /* error - more than one 'inc' value! */
}
}
}
if (base == (-1)) return 0xfe; /* error - no row in pass! */
@ -11312,7 +11346,8 @@ png_row_in_interlace_pass(png_uint_32 y, int pass)
int x;
y &= 7;
++pass;
for (x=0; x<8; ++x) if (adam7[y][x] == pass)
for (x=0; x<8; ++x)
if (adam7[y][x] == pass)
return 1;
return 0;
@ -11325,7 +11360,8 @@ png_col_in_interlace_pass(png_uint_32 x, int pass)
int y;
x &= 7;
++pass;
for (y=0; y<8; ++y) if (adam7[y][x] == pass)
for (y=0; y<8; ++y)
if (adam7[y][x] == pass)
return 1;
return 0;
@ -11340,12 +11376,18 @@ png_pass_rows(png_uint_32 height, int pass)
height &= 7;
++pass;
for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass)
for (y=0; y<8; ++y)
{
for (x=0; x<8; ++x)
{
if (adam7[y][x] == pass)
{
rows += tiles;
if (y < height) ++rows;
break; /* i.e. break the 'x', column, loop. */
}
}
}
return rows;
}
@ -11359,12 +11401,18 @@ png_pass_cols(png_uint_32 width, int pass)
width &= 7;
++pass;
for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass)
for (x=0; x<8; ++x)
{
for (y=0; y<8; ++y)
{
if (adam7[y][x] == pass)
{
cols += tiles;
if (x < width) ++cols;
break; /* i.e. break the 'y', row, loop. */
}
}
}
return cols;
}

View File

@ -1,9 +1,8 @@
/* readpng.c
*
* Copyright (c) 2013 John Cunningham Bowler
*
* Last changed in libpng 1.6.1 [March 28, 2013]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h

View File

@ -1,10 +1,9 @@
/* tarith.c
*
* Copyright (c) 2021 Cosmin Truta
* Copyright (c) 2011-2013 John Cunningham Bowler
*
* Last changed in libpng 1.6.0 [February 14, 2013]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
@ -88,6 +87,7 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
int minorarith = 0;
while (--argc > 0)
{
if (strcmp(*++argv, "-a") == 0)
showall = 1;
else if (strcmp(*argv, "-e") == 0 && argc > 0)
@ -105,6 +105,7 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
fprintf(stderr, "unknown argument %s\n", *argv);
return 1;
}
}
do
{
@ -130,8 +131,8 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
*/
if (buffer[precision+7] != 71)
{
fprintf(stderr, "%g[%d] -> '%s'[%lu] buffer overflow\n", test,
precision, buffer, (unsigned long)strlen(buffer));
fprintf(stderr, "%g[%d] -> '%s'[%lu] buffer overflow\n",
test, precision, buffer, (unsigned long)strlen(buffer));
failed = 1;
}
@ -146,16 +147,16 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
if (test >= 0 && strcmp(buffer, "inf") ||
test < 0 && strcmp(buffer, "-inf"))
{
fprintf(stderr, "%g[%d] -> '%s' but expected 'inf'\n", test,
precision, buffer);
fprintf(stderr, "%g[%d] -> '%s' but expected 'inf'\n",
test, precision, buffer);
failed = 1;
}
}
else if (!png_check_fp_number(buffer, precision+10, &state, &index) ||
buffer[index] != 0)
{
fprintf(stderr, "%g[%d] -> '%s' but has bad format ('%c')\n", test,
precision, buffer, buffer[index]);
fprintf(stderr, "%g[%d] -> '%s' but has bad format ('%c')\n",
test, precision, buffer, buffer[index]);
failed = 1;
}
else if (PNG_FP_IS_NEGATIVE(state) && !(test < 0))
@ -187,7 +188,7 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
/* Check the result against the original. */
double out = atof(buffer);
double change = fabs((out - test)/test);
double allow = .5/pow(10,
double allow = .5 / pow(10,
(precision >= DBL_DIG) ? DBL_DIG-1 : precision-1);
/* NOTE: if you hit this error case are you compiling with gcc
@ -257,8 +258,9 @@ skip:
}
while (--count);
printf("Tested %d finite values, %d non-finite, %d OK (%d failed) %d minor "
"arithmetic errors\n", finite, nonfinite, ok, failcount, minorarith);
printf("Tested %d finite values, %d non-finite, %d OK (%d failed) "
"%d minor arithmetic errors\n",
finite, nonfinite, ok, failcount, minorarith);
printf(" Error with >=%d digit precision %.2f%%\n", DBL_DIG, max_abs);
printf(" Error with < %d digit precision %.2f%%\n", DBL_DIG, max);
@ -371,8 +373,8 @@ static int check_one_character(checkfp_command *co, checkfp_control c, int ch)
/* This should never fail (it's a serious bug if it does): */
if (index != 0 && index != 1)
{
fprintf(stderr, "%s: read beyond end of string (%lu)\n", co->number,
(unsigned long)index);
fprintf(stderr, "%s: read beyond end of string (%lu)\n",
co->number, (unsigned long)index);
return 0;
}
@ -503,8 +505,8 @@ static int check_one_character(checkfp_command *co, checkfp_control c, int ch)
if (number_is_valid != c.number_was_valid)
{
fprintf(stderr,
"%s: character '%c' [0x%.2x] changed number validity\n", co->number,
ch, ch);
"%s: character '%c' [0x%.2x] changed number validity\n",
co->number, ch, ch);
return 0;
}
@ -521,11 +523,14 @@ static int check_all_characters(checkfp_command *co, checkfp_control c)
{
int ch;
if (c.cnumber+4 < sizeof co->number) for (ch=0; ch<256; ++ch)
if (c.cnumber+4 < sizeof co->number)
{
for (ch=0; ch<256; ++ch)
{
if (!check_one_character(co, c, ch))
return 0;
}
}
return 1;
}
@ -539,11 +544,14 @@ static int check_some_characters(checkfp_command *co, checkfp_control c,
if (c.cnumber+4 < sizeof co->number && c.limit >= 0)
{
if (c.limit > 0) for (i=0; tests[i]; ++i)
if (c.limit > 0)
{
for (i=0; tests[i]; ++i)
{
if (!check_one_character(co, c, tests[i]))
return 0;
}
}
/* At the end check all the characters. */
else
@ -687,25 +695,25 @@ int validation_muldiv(int count, int argc, char **argv)
ok = 0, ++overflow, fpround = fp/*misleading*/;
if (verbose)
fprintf(stderr, "TEST %d * %d / %d -> %lld (%s)\n", a, times, div,
fp, ok ? "ok" : "overflow");
fprintf(stderr, "TEST %d * %d / %d -> %lld (%s)\n",
a, times, div, fp, ok ? "ok" : "overflow");
++tested;
if (png_muldiv(&result, a, times, div) != ok)
{
++error;
if (ok)
fprintf(stderr, "%d * %d / %d -> overflow (expected %lld)\n", a,
times, div, fp);
fprintf(stderr, "%d * %d / %d -> overflow (expected %lld)\n",
a, times, div, fp);
else
fprintf(stderr, "%d * %d / %d -> %d (expected overflow %lld)\n", a,
times, div, result, fp);
fprintf(stderr, "%d * %d / %d -> %d (expected overflow %lld)\n",
a, times, div, result, fp);
}
else if (ok && result != fpround)
{
++error;
fprintf(stderr, "%d * %d / %d -> %d not %lld\n", a, times, div, result,
fp);
fprintf(stderr, "%d * %d / %d -> %d not %lld\n",
a, times, div, result, fp);
}
else
++passed;
@ -721,8 +729,8 @@ int validation_muldiv(int count, int argc, char **argv)
}
while (--count > 0);
printf("%d tests including %d overflows, %d passed, %d failed (%d 64-bit "
"errors)\n", tested, overflow, passed, error, error64);
printf("%d tests including %d overflows, %d passed, %d failed "
"(%d 64-bit errors)\n", tested, overflow, passed, error, error64);
return 0;
}
@ -821,8 +829,9 @@ int validation_gamma(int argc, char **argv)
{
if (error > .68) /* By experiment error is less than .68 */
{
fprintf(stderr, "16-bit log error: %d: got %u, expected %f"
" error: %f\n", i, png_log16bit(i), correct, error);
fprintf(stderr,
"16-bit log error: %d: got %u, expected %f error: %f\n",
i, png_log16bit(i), correct, error);
}
}
}
@ -841,8 +850,9 @@ int validation_gamma(int argc, char **argv)
maxerr = fabs(error);
if (fabs(error) > 1883) /* By experiment. */
{
fprintf(stderr, "32-bit exp error: %d: got %u, expected %f"
" error: %f\n", i, png_exp(i), correct, error);
fprintf(stderr,
"32-bit exp error: %d: got %u, expected %f error: %f\n",
i, png_exp(i), correct, error);
}
}
@ -859,8 +869,9 @@ int validation_gamma(int argc, char **argv)
maxerr = fabs(error);
if (fabs(error) > .50002) /* By experiment */
{
fprintf(stderr, "8-bit exp error: %d: got %u, expected %f"
" error: %f\n", i, png_exp8bit(i), correct, error);
fprintf(stderr,
"8-bit exp error: %d: got %u, expected %f error: %f\n",
i, png_exp8bit(i), correct, error);
}
}
@ -877,8 +888,9 @@ int validation_gamma(int argc, char **argv)
maxerr = fabs(error);
if (fabs(error) > .524) /* By experiment */
{
fprintf(stderr, "16-bit exp error: %d: got %u, expected %f"
" error: %f\n", i, png_exp16bit(i), correct, error);
fprintf(stderr,
"16-bit exp error: %d: got %u, expected %f error: %f\n",
i, png_exp16bit(i), correct, error);
}
}

View File

@ -1,9 +1,8 @@
/* timepng.c
*
* Copyright (c) 2013,2016 John Cunningham Bowler
*
* Last changed in libpng 1.6.22 [May 26, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h