From 0fa3c0f698c2ca618a0fa44e10a822678df85373 Mon Sep 17 00:00:00 2001 From: Cosmin Truta Date: Thu, 15 Feb 2024 21:53:24 +0200 Subject: [PATCH] chore: Clean up the spurious uses of `sizeof(png_byte)`; fix the manual By definition, `sizeof(png_byte)` is 1. Remove all the occurences of `sizeof(png_byte)` from the code, and fix a related typo in the libpng manual. Also update the main .editorconfig file to reflect the fixing expected by a FIXME note. --- .editorconfig | 3 +-- libpng-manual.txt | 4 ++-- libpng.3 | 4 ++-- pngrtran.c | 17 +++++++---------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/.editorconfig b/.editorconfig index 324bdf7d59..7f9f1c9bfe 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,8 +16,7 @@ indent_style = space [*.[chS]] indent_style = space max_doc_length = 80 -max_line_length = 81 -# FIXME: max_line_length should be 80 +max_line_length = 80 [*.dfa] indent_style = space diff --git a/libpng-manual.txt b/libpng-manual.txt index eb24ef4831..d2918ce316 100644 --- a/libpng-manual.txt +++ b/libpng-manual.txt @@ -1178,11 +1178,11 @@ where row_pointers is an array of pointers to the pixel data for each row: If you know your image size and pixel size ahead of time, you can allocate row_pointers prior to calling png_read_png() with - if (height > PNG_UINT_32_MAX/(sizeof (png_byte))) + if (height > PNG_UINT_32_MAX / (sizeof (png_bytep))) png_error(png_ptr, "Image is too tall to process in memory"); - if (width > PNG_UINT_32_MAX/pixel_size) + if (width > PNG_UINT_32_MAX / pixel_size) png_error(png_ptr, "Image is too wide to process in memory"); diff --git a/libpng.3 b/libpng.3 index 57d06f2db6..8875b219a1 100644 --- a/libpng.3 +++ b/libpng.3 @@ -1697,11 +1697,11 @@ where row_pointers is an array of pointers to the pixel data for each row: If you know your image size and pixel size ahead of time, you can allocate row_pointers prior to calling png_read_png() with - if (height > PNG_UINT_32_MAX/(sizeof (png_byte))) + if (height > PNG_UINT_32_MAX / (sizeof (png_bytep))) png_error(png_ptr, "Image is too tall to process in memory"); - if (width > PNG_UINT_32_MAX/pixel_size) + if (width > PNG_UINT_32_MAX / pixel_size) png_error(png_ptr, "Image is too wide to process in memory"); diff --git a/pngrtran.c b/pngrtran.c index 74cca476b1..041f9306c1 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -440,7 +440,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette, int i; png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr, - (png_alloc_size_t)((png_uint_32)num_palette * (sizeof (png_byte)))); + (png_alloc_size_t)num_palette); for (i = 0; i < num_palette; i++) png_ptr->quantize_index[i] = (png_byte)i; } @@ -457,7 +457,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette, /* Initialize an array to sort colors */ png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr, - (png_alloc_size_t)((png_uint_32)num_palette * (sizeof (png_byte)))); + (png_alloc_size_t)num_palette); /* Initialize the quantize_sort array */ for (i = 0; i < num_palette; i++) @@ -591,11 +591,9 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette, /* Initialize palette index arrays */ png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr, - (png_alloc_size_t)((png_uint_32)num_palette * - (sizeof (png_byte)))); + (png_alloc_size_t)num_palette); png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr, - (png_alloc_size_t)((png_uint_32)num_palette * - (sizeof (png_byte)))); + (png_alloc_size_t)num_palette); /* Initialize the sort array */ for (i = 0; i < num_palette; i++) @@ -760,12 +758,11 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette, size_t num_entries = ((size_t)1 << total_bits); png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr, - (png_alloc_size_t)(num_entries * (sizeof (png_byte)))); + (png_alloc_size_t)(num_entries)); - distance = (png_bytep)png_malloc(png_ptr, (png_alloc_size_t)(num_entries * - (sizeof (png_byte)))); + distance = (png_bytep)png_malloc(png_ptr, (png_alloc_size_t)num_entries); - memset(distance, 0xff, num_entries * (sizeof (png_byte))); + memset(distance, 0xff, num_entries); for (i = 0; i < num_palette; i++) {