Skip to content

Commit

Permalink
chore: Clean up the spurious uses of sizeof(png_byte); fix the manual
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ctruta committed Feb 15, 2024
1 parent 4191872 commit 0fa3c0f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions libpng-manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions libpng.3
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
17 changes: 7 additions & 10 deletions pngrtran.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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++)
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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++)
{
Expand Down

0 comments on commit 0fa3c0f

Please sign in to comment.