From e2bb5e7512a48dcfe191065decac9cf78a68fd12 Mon Sep 17 00:00:00 2001 From: Cosmin Truta Date: Fri, 12 Mar 2021 22:54:32 -0500 Subject: [PATCH] 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. --- contrib/libtests/gentests.sh | 2 - contrib/libtests/makepng.c | 57 +++--- contrib/libtests/pngimage.c | 67 ++++---- contrib/libtests/pngstest.c | 28 +-- contrib/libtests/pngunknown.c | 61 ++++--- contrib/libtests/pngvalid.c | 314 ++++++++++++++++++++-------------- contrib/libtests/readpng.c | 3 +- contrib/libtests/tarith.c | 98 ++++++----- contrib/libtests/timepng.c | 3 +- 9 files changed, 360 insertions(+), 273 deletions(-) diff --git a/contrib/libtests/gentests.sh b/contrib/libtests/gentests.sh index f0f8d2395..eba7ce50c 100755 --- a/contrib/libtests/gentests.sh +++ b/contrib/libtests/gentests.sh @@ -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 diff --git a/contrib/libtests/makepng.c b/contrib/libtests/makepng.c index 312062bda..088df531a 100644 --- a/contrib/libtests/makepng.c +++ b/contrib/libtests/makepng.c @@ -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,25 +297,28 @@ generate_palette(png_colorp palette, png_bytep trans, int bit_depth, unsigned int x, y; volatile unsigned int ip = 0; - for (x=0; x #include #include @@ -317,11 +318,10 @@ transform_name(int t) t &= -t; /* first set bit */ - for (i=0; ibit_depth; unsigned int i; - for (i=0; i 0x%.2x", @@ -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,8 +1694,9 @@ main(int argc, char **argv) printf("%s: pngimage ", pass ? "PASS" : "FAIL"); - for (j=1; j #include @@ -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); @@ -2712,12 +2713,12 @@ compare_two_images(Image *a, Image *b, int via_linear, else if (y >= b->image.colormap_entries) { 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); - } + } result = 0; } @@ -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) - btoa[bloc[i]] = aloc[i]; /* may be '4' for alpha */ + 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)) diff --git a/contrib/libtests/pngunknown.c b/contrib/libtests/pngunknown.c index 05bdd833d..dfa9d10a1 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.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,27 +549,30 @@ 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) { - png_uint_32 flag = chunk_info[chunk].flag; + if (!discard) /* stupidity to stop a GCC warning */ + { + png_uint_32 flag = chunk_info[chunk].flag; - if (pc->location & PNG_AFTER_IDAT) - d->after_IDAT |= flag; + if (pc->location & PNG_AFTER_IDAT) + d->after_IDAT |= flag; - else - d->before_IDAT |= flag; + else + d->before_IDAT |= flag; + } } /* However if there is no support to store unknown chunks don't ask libpng to @@ -841,8 +846,9 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/, { png_uint_32 y; - for (y=0; ypng_ptr, NULL, NULL); + for (y=0; ypng_ptr, NULL, NULL); } } } /* interlaced */ @@ -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, - "sAPI", "bKGD=save", "cHRM=save", "gAMA=save", "all=discard", "iCCP=save", - "sBIT=save", "sRGB=save", "eXIf=save", 0, - 0/*end*/ + "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", 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,8 +1159,9 @@ 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) - usage(d.program, "extra arguments"); + else if (default_tests) + if (argc != 1) + usage(d.program, "extra arguments"); /* The name of the test file is the last argument; remove it. */ d.file = argv[--argc]; @@ -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); diff --git a/contrib/libtests/pngvalid.c b/contrib/libtests/pngvalid.c index 9a2da6a02..86e2f7516 100644 --- a/contrib/libtests/pngvalid.c +++ b/contrib/libtests/pngvalid.c @@ -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,47 +5878,50 @@ 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]) { - /* 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*/, - pm->use_update_info); + 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*/, + pm->use_update_info); - if (fail(pm)) - return 0; + 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*/, - pm->use_update_info); + 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)) - return 0; + if (fail(pm)) + return 0; - /* Now validate the interlaced read side - do_interlace true, - * 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*/, - pm->use_update_info); + /* Now validate the interlaced read side - do_interlace true, + * 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*/, + pm->use_update_info); - if (fail(pm)) - return 0; + if (fail(pm)) + return 0; -# 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*/, - pm->use_update_info); +# 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*/, + pm->use_update_info); - if (fail(pm)) - return 0; -# endif + if (fail(pm)) + return 0; +# endif + } } } @@ -5928,45 +5932,48 @@ 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]) { -# 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: - */ -# if CAN_WRITE_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); + 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: + */ +# if CAN_WRITE_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)) - return 0; -# endif -# endif /* READ_INTERLACING */ + if (fail(pm)) + return 0; +# endif +# endif /* READ_INTERLACING */ -# 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*/, - pm->use_update_info); +# 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*/, + pm->use_update_info); - if (fail(pm)) - return 0; -# endif + if (fail(pm)) + return 0; +# endif -# 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*/, - pm->use_update_info); +# 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*/, + pm->use_update_info); - if (fail(pm)) - return 0; -# endif -# endif /* READ_INTERLACING */ + if (fail(pm)) + return 0; +# endif +# endif /* READ_INTERLACING */ + } } } @@ -10650,16 +10657,21 @@ static void perform_gamma_transform_tests(png_modifier *pm) { unsigned int i, j; - for (i=0; ingamma_tests; ++i) for (j=0; jngamma_tests; ++j) - if (i != j) + for (i=0; ingamma_tests; ++i) + { + for (j=0; jngamma_tests; ++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*/); + 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*/); - if (fail(pm)) - return; + if (fail(pm)) + return; + } } + } } } @@ -10688,14 +10700,17 @@ static void perform_gamma_sbit_tests(png_modifier *pm) { unsigned int j; - for (j=0; jngamma_tests; ++j) if (i != j) + for (j=0; jngamma_tests; ++j) { - gamma_transform_test(pm, colour_type, bit_depth, npalette, - pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], - sbit, pm->use_input_precision_sbit, 0 /*scale16*/); + if (i != j) + { + gamma_transform_test(pm, colour_type, bit_depth, npalette, + pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], + sbit, pm->use_input_precision_sbit, 0 /*scale16*/); - if (fail(pm)) - return; + if (fail(pm)) + return; + } } } } @@ -10947,14 +10962,17 @@ 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; ingamma_tests; ++i) for (j=0; jngamma_tests; ++j) + for (i=0; ingamma_tests; ++i) { - gamma_composition_test(pm, colour_type, bit_depth, palette_number, - pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], - pm->use_input_precision, do_background, expand_16); + for (j=0; jngamma_tests; ++j) + { + gamma_composition_test(pm, colour_type, bit_depth, palette_number, + pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], + pm->use_input_precision, do_background, expand_16); - if (fail(pm)) - return; + if (fail(pm)) + return; + } } } } @@ -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,8 +11201,10 @@ 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) - return y; + for (y=0; y<8; ++y) + for (x=0; x<8; ++x) + if (adam7[y][x] == pass) + return y; return 0xf; } @@ -11193,8 +11213,10 @@ 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) - return x; + for (x=0; x<8; ++x) + for (y=0; y<8; ++y) + if (adam7[y][x] == pass) + return x; return 0xf; } @@ -11203,18 +11225,24 @@ 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) { - if (base == (-1)) - base = y; - else if (base == y) - {} - else if (inc == y-base) - base=y; - else if (inc == 8) - inc = y-base, base=y; - else if (inc != y-base) - return 0xff; /* error - more than one 'inc' value! */ + for (x=0; x<8; ++x) + { + if (adam7[y][x] == pass) + { + if (base == (-1)) + base = y; + else if (base == y) + {} + else if (inc == y-base) + base=y; + else if (inc == 8) + inc = y-base, base=y; + else if (inc != y-base) + return 0xff; /* error - more than one 'inc' value! */ + } + } } if (base == (-1)) return 0xfe; /* error - no row in pass! */ @@ -11237,18 +11265,24 @@ 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) { - if (base == (-1)) - base = x; - else if (base == x) - {} - else if (inc == x-base) - base=x; - else if (inc == 8) - inc = x-base, base=x; - else if (inc != x-base) - return 0xff; /* error - more than one 'inc' value! */ + for (y=0; y<8; ++y) + { + if (adam7[y][x] == pass) + { + if (base == (-1)) + base = x; + else if (base == x) + {} + else if (inc == x-base) + base=x; + else if (inc == 8) + inc = x-base, base=x; + else if (inc != x-base) + return 0xff; /* error - more than one 'inc' value! */ + } + } } if (base == (-1)) return 0xfe; /* error - no row in pass! */ @@ -11312,8 +11346,9 @@ 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) - return 1; + for (x=0; x<8; ++x) + if (adam7[y][x] == pass) + return 1; return 0; } @@ -11325,8 +11360,9 @@ 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) - return 1; + for (y=0; y<8; ++y) + if (adam7[y][x] == pass) + return 1; return 0; } @@ -11340,11 +11376,17 @@ 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) { - rows += tiles; - if (y < height) ++rows; - break; /* i.e. break the 'x', column, loop. */ + 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,11 +11401,17 @@ 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) { - cols += tiles; - if (x < width) ++cols; - break; /* i.e. break the 'y', row, loop. */ + 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; @@ -11811,21 +11859,21 @@ int main(int argc, char **argv) #ifdef PNG_READ_TRANSFORMS_SUPPORTED else if (strncmp(*argv, "--transform-disable=", sizeof "--transform-disable") == 0) - { + { pm.test_transform = 1; transform_disable(*argv + sizeof "--transform-disable"); - } + } else if (strncmp(*argv, "--transform-enable=", sizeof "--transform-enable") == 0) - { + { pm.test_transform = 1; transform_enable(*argv + sizeof "--transform-enable"); - } + } #endif /* PNG_READ_TRANSFORMS_SUPPORTED */ else if (strcmp(*argv, "--gamma") == 0) - { + { /* Just do two gamma tests here (2.2 and linear) for speed: */ pm.ngamma_tests = 2U; pm.test_gamma_threshold = 1; @@ -11834,7 +11882,7 @@ int main(int argc, char **argv) pm.test_gamma_scale16 = 1; pm.test_gamma_background = 1; /* composition */ pm.test_gamma_alpha_mode = 1; - } + } else if (strcmp(*argv, "--nogamma") == 0) pm.ngamma_tests = 0; diff --git a/contrib/libtests/readpng.c b/contrib/libtests/readpng.c index 60a2d46c5..7528e90bd 100644 --- a/contrib/libtests/readpng.c +++ b/contrib/libtests/readpng.c @@ -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 diff --git a/contrib/libtests/tarith.c b/contrib/libtests/tarith.c index c03f05a80..ead77e9a5 100644 --- a/contrib/libtests/tarith.c +++ b/contrib/libtests/tarith.c @@ -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,10 +523,13 @@ 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) { - if (!check_one_character(co, c, ch)) - return 0; + for (ch=0; ch<256; ++ch) + { + if (!check_one_character(co, c, ch)) + return 0; + } } return 1; @@ -539,10 +544,13 @@ 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) { - if (!check_one_character(co, c, tests[i])) - return 0; + for (i=0; tests[i]; ++i) + { + if (!check_one_character(co, c, tests[i])) + return 0; + } } /* At the end check all the characters. */ @@ -616,10 +624,10 @@ int validation_muldiv(int count, int argc, char **argv) png_int_32 times, div; while (--argc > 0) - { - fprintf(stderr, "unknown argument %s\n", *++argv); - return 1; - } + { + fprintf(stderr, "unknown argument %s\n", *++argv); + return 1; + } /* Find out about the random number generator. */ randbuffer = RAND_MAX; @@ -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); } } diff --git a/contrib/libtests/timepng.c b/contrib/libtests/timepng.c index 23d8b17b1..a592c8cc4 100644 --- a/contrib/libtests/timepng.c +++ b/contrib/libtests/timepng.c @@ -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