Skip to content

Commit

Permalink
[libpng16] Replace the remaining uses of png_size_t with size_t
Browse files Browse the repository at this point in the history
In v1.6.0, size_t became a required type. It should be used
consistently. To maintain backwards compatibility, png_size_t
is still maintained in deprecated form.
  • Loading branch information
ctruta committed Jun 18, 2018
1 parent 916117d commit a74aa9a
Show file tree
Hide file tree
Showing 36 changed files with 362 additions and 367 deletions.
10 changes: 5 additions & 5 deletions contrib/libtests/makepng.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
int passes = 1;
# endif /* !WRITE_INTERLACING */
int pass;
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);

row = malloc(rowbytes);

Expand Down Expand Up @@ -1094,7 +1094,7 @@ load_file(png_const_charp name, png_bytepp result)
return 0;
}

static png_size_t
static size_t
load_fake(png_charp param, png_bytepp profile)
{
char *endptr = NULL;
Expand Down Expand Up @@ -1164,7 +1164,7 @@ insert_iCCP(png_structp png_ptr, png_infop info_ptr, int nparams,
{
case '<':
{
png_size_t filelen = load_file(params[1]+1, &profile);
size_t filelen = load_file(params[1]+1, &profile);
if (filelen > 0xfffffffc) /* Maximum profile length */
{
fprintf(stderr, "%s: file too long (%lu) for an ICC profile\n",
Expand All @@ -1179,7 +1179,7 @@ insert_iCCP(png_structp png_ptr, png_infop info_ptr, int nparams,
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
{
png_size_t fake_len = load_fake(params[1], &profile);
size_t fake_len = load_fake(params[1], &profile);

if (fake_len > 0) /* else a simple parameter */
{
Expand Down Expand Up @@ -1274,7 +1274,7 @@ set_text(png_structp png_ptr, png_infop info_ptr, png_textp text,
case '5': case '6': case '7': case '8': case '9':
{
png_bytep data = NULL;
png_size_t fake_len = load_fake(param, &data);
size_t fake_len = load_fake(param, &data);

if (fake_len > 0) /* else a simple parameter */
{
Expand Down
10 changes: 5 additions & 5 deletions contrib/libtests/pngimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ struct display
png_structp original_pp; /* used on the original read */
png_infop original_ip; /* set by the original read */

png_size_t original_rowbytes; /* of the original rows: */
size_t original_rowbytes; /* of the original rows: */
png_bytepp original_rows; /* from the original read */

/* Original chunks valid */
Expand Down Expand Up @@ -807,7 +807,7 @@ display_cache_file(struct display *dp, const char *filename)

static void
buffer_read(struct display *dp, struct buffer *bp, png_bytep data,
png_size_t size)
size_t size)
{
struct buffer_list *last = bp->current;
size_t read_count = bp->read_count;
Expand Down Expand Up @@ -855,7 +855,7 @@ buffer_read(struct display *dp, struct buffer *bp, png_bytep data,
}

static void PNGCBAPI
read_function(png_structp pp, png_bytep data, png_size_t size)
read_function(png_structp pp, png_bytep data, size_t size)
{
buffer_read(get_dp(pp), get_buffer(pp), data, size);
}
Expand Down Expand Up @@ -1267,7 +1267,7 @@ compare_read(struct display *dp, int applied_transforms)
#ifdef PNG_WRITE_PNG_SUPPORTED
static void
buffer_write(struct display *dp, struct buffer *buffer, png_bytep data,
png_size_t size)
size_t size)
/* Generic write function used both from the write callback provided to
* libpng and from the generic read code.
*/
Expand Down Expand Up @@ -1311,7 +1311,7 @@ buffer_write(struct display *dp, struct buffer *buffer, png_bytep data,
}

static void PNGCBAPI
write_function(png_structp pp, png_bytep data, png_size_t size)
write_function(png_structp pp, png_bytep data, size_t size)
{
buffer_write(get_dp(pp), get_buffer(pp), data, size);
}
Expand Down
8 changes: 4 additions & 4 deletions contrib/libtests/pngstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,11 @@ typedef struct
int stride_extra;
FILE *input_file;
png_voidp input_memory;
png_size_t input_memory_size;
size_t input_memory_size;
png_bytep buffer;
ptrdiff_t stride;
png_size_t bufsize;
png_size_t allocsize;
size_t bufsize;
size_t allocsize;
char tmpfile_name[32];
png_uint_16 colormap[256*4];
}
Expand Down Expand Up @@ -665,7 +665,7 @@ static void initimage(Image *image, png_uint_32 opts, const char *file_name,
static void
allocbuffer(Image *image)
{
png_size_t size = PNG_IMAGE_BUFFER_SIZE(image->image, image->stride);
size_t size = PNG_IMAGE_BUFFER_SIZE(image->image, image->stride);

if (size+32 > image->bufsize)
{
Expand Down
53 changes: 26 additions & 27 deletions contrib/libtests/pngvalid.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ typedef struct png_store_file
unsigned int IDAT_bits; /* Number of bits in IDAT size */
png_uint_32 IDAT_size; /* Total size of IDAT data */
png_uint_32 id; /* must be correct (see FILEID) */
png_size_t datacount; /* In this (the last) buffer */
size_t datacount; /* In this (the last) buffer */
png_store_buffer data; /* Last buffer in file */
int npalette; /* Number of entries in palette */
store_palette_entry* palette; /* May be NULL */
Expand Down Expand Up @@ -777,10 +777,10 @@ typedef struct png_store
png_infop piread;
png_store_file* current; /* Set when reading */
png_store_buffer* next; /* Set when reading */
png_size_t readpos; /* Position in *next */
size_t readpos; /* Position in *next */
png_byte* image; /* Buffer for reading interlaced images */
png_size_t cb_image; /* Size of this buffer */
png_size_t cb_row; /* Row size of the image(s) */
size_t cb_image; /* Size of this buffer */
size_t cb_row; /* Row size of the image(s) */
uLong IDAT_crc;
png_uint_32 IDAT_len; /* Used when re-chunking IDAT chunks */
png_uint_32 IDAT_pos; /* Used when re-chunking IDAT chunks */
Expand All @@ -791,7 +791,7 @@ typedef struct png_store
png_store_file* saved;
png_structp pwrite; /* Used when writing a new file */
png_infop piwrite;
png_size_t writepos; /* Position in .new */
size_t writepos; /* Position in .new */
char wname[FILE_NAME_SIZE];
png_store_buffer new; /* The end of the new PNG file being written. */
store_pool write_memory_pool;
Expand Down Expand Up @@ -1125,7 +1125,7 @@ static png_bytep
store_image_row(const png_store* ps, png_const_structp pp, int nImage,
png_uint_32 y)
{
png_size_t coffset = (nImage * ps->image_h + y) * (ps->cb_row + 5) + 2;
size_t coffset = (nImage * ps->image_h + y) * (ps->cb_row + 5) + 2;

if (ps->image == NULL)
png_error(pp, "no allocated image");
Expand Down Expand Up @@ -1160,9 +1160,9 @@ store_image_free(png_store *ps, png_const_structp pp)

static void
store_ensure_image(png_store *ps, png_const_structp pp, int nImages,
png_size_t cbRow, png_uint_32 cRows)
size_t cbRow, png_uint_32 cRows)
{
png_size_t cb = nImages * cRows * (cbRow + 5);
size_t cb = nImages * cRows * (cbRow + 5);

if (ps->cb_image < cb)
{
Expand Down Expand Up @@ -1234,7 +1234,7 @@ store_image_check(const png_store* ps, png_const_structp pp, int iImage)
png_error(pp, "image overwrite");
else
{
png_size_t cbRow = ps->cb_row;
size_t cbRow = ps->cb_row;
png_uint_32 rows = ps->image_h;

image += iImage * (cbRow+5) * ps->image_h;
Expand Down Expand Up @@ -1278,7 +1278,7 @@ valid_chunktype(png_uint_32 chunktype)
}

static void PNGCBAPI
store_write(png_structp ppIn, png_bytep pb, png_size_t st)
store_write(png_structp ppIn, png_bytep pb, size_t st)
{
png_const_structp pp = ppIn;
png_store *ps = voidcast(png_store*, png_get_io_ptr(pp));
Expand Down Expand Up @@ -1346,13 +1346,13 @@ store_write(png_structp ppIn, png_bytep pb, png_size_t st)

else /* chunkpos >= 8 */
{
png_size_t cb = st;
size_t cb = st;

if (cb > STORE_BUFFER_SIZE - writepos)
cb = STORE_BUFFER_SIZE - writepos;

if (cb > chunklen - chunkpos/* bytes left in chunk*/)
cb = (png_size_t)/*SAFE*/(chunklen - chunkpos);
cb = (size_t)/*SAFE*/(chunklen - chunkpos);

memcpy(ps->new.buffer + writepos, pb, cb);
chunkpos += (png_uint_32)/*SAFE*/cb;
Expand Down Expand Up @@ -1440,7 +1440,7 @@ store_read_buffer_next(png_store *ps)
* during progressive read, where the io_ptr is set internally by libpng.
*/
static void
store_read_imp(png_store *ps, png_bytep pb, png_size_t st)
store_read_imp(png_store *ps, png_bytep pb, size_t st)
{
if (ps->current == NULL || ps->next == NULL)
png_error(ps->pread, "store state damaged");
Expand All @@ -1463,14 +1463,13 @@ store_read_imp(png_store *ps, png_bytep pb, png_size_t st)
}
}

static png_size_t
store_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,
const png_size_t min)
static size_t
store_read_chunk(png_store *ps, png_bytep pb, size_t max, size_t min)
{
png_uint_32 chunklen = ps->chunklen;
png_uint_32 chunktype = ps->chunktype;
png_uint_32 chunkpos = ps->chunkpos;
png_size_t st = max;
size_t st = max;

if (st > 0) do
{
Expand Down Expand Up @@ -1601,8 +1600,8 @@ store_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,

store_read_imp(ps, pb, avail);
ps->IDAT_crc = crc32(ps->IDAT_crc, pb, avail);
pb += (png_size_t)/*SAFE*/avail;
st -= (png_size_t)/*SAFE*/avail;
pb += (size_t)/*SAFE*/avail;
st -= (size_t)/*SAFE*/avail;
chunkpos += (png_uint_32)/*SAFE*/avail;
IDAT_size -= (png_uint_32)/*SAFE*/avail;
IDAT_pos += (png_uint_32)/*SAFE*/avail;
Expand Down Expand Up @@ -1669,10 +1668,10 @@ store_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,

else /* Return chunk bytes, including the CRC */
{
png_size_t avail = st;
size_t avail = st;

if (avail > chunklen - chunkpos)
avail = (png_size_t)/*SAFE*/(chunklen - chunkpos);
avail = (size_t)/*SAFE*/(chunklen - chunkpos);

store_read_imp(ps, pb, avail);
pb += avail;
Expand All @@ -1698,7 +1697,7 @@ store_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,
}

static void PNGCBAPI
store_read(png_structp ppIn, png_bytep pb, png_size_t st)
store_read(png_structp ppIn, png_bytep pb, size_t st)
{
png_const_structp pp = ppIn;
png_store *ps = voidcast(png_store*, png_get_io_ptr(pp));
Expand All @@ -1724,7 +1723,7 @@ store_progressive_read(png_store *ps, png_structp pp, png_infop pi)
while (store_read_buffer_avail(ps) > 0)
{
static png_uint_32 noise = 2;
png_size_t cb;
size_t cb;
png_byte buffer[512];

/* Generate 15 more bits of stuff: */
Expand Down Expand Up @@ -2991,7 +2990,7 @@ modifier_setbuffer(png_modifier *pm)
* png_struct.
*/
static void
modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
modifier_read_imp(png_modifier *pm, png_bytep pb, size_t st)
{
while (st > 0)
{
Expand Down Expand Up @@ -3137,7 +3136,7 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
*/
if (len+12 <= sizeof pm->buffer)
{
png_size_t s = len+12-pm->buffer_count;
size_t s = len+12-pm->buffer_count;
store_read_chunk(&pm->this, pm->buffer+pm->buffer_count, s, s);
pm->buffer_count = len+12;

Expand Down Expand Up @@ -3196,7 +3195,7 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)

/* The callback: */
static void PNGCBAPI
modifier_read(png_structp ppIn, png_bytep pb, png_size_t st)
modifier_read(png_structp ppIn, png_bytep pb, size_t st)
{
png_const_structp pp = ppIn;
png_modifier *pm = voidcast(png_modifier*, png_get_io_ptr(pp));
Expand Down Expand Up @@ -3226,7 +3225,7 @@ modifier_progressive_read(png_modifier *pm, png_structp pp, png_infop pi)
for (;;)
{
static png_uint_32 noise = 1;
png_size_t cb, cbAvail;
size_t cb, cbAvail;
png_byte buffer[512];

/* Generate 15 more bits of stuff: */
Expand Down
2 changes: 1 addition & 1 deletion contrib/libtests/readpng.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ read_png(FILE *fp)
png_read_info(png_ptr, info_ptr);

{
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);

/* Failure to initialize these is harmless */
row = malloc(rowbytes);
Expand Down
4 changes: 2 additions & 2 deletions contrib/libtests/tarith.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int validation_ascii_to_fp(int count, int argc, char **argv)

do
{
png_size_t index;
size_t index;
int state, failed = 0;
char buffer[64];

Expand Down Expand Up @@ -329,7 +329,7 @@ static int check_one_character(checkfp_command *co, checkfp_control c, int ch)
{
/* Test this character (ch) to ensure the parser does the correct thing.
*/
png_size_t index = 0;
size_t index = 0;
const char test = (char)ch;
const int number_is_valid = png_check_fp_number(&test, 1, &c.state, &index);
const int character_accepted = (index == 1);
Expand Down
4 changes: 2 additions & 2 deletions contrib/libtests/timepng.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ typedef struct
} io_data;

static PNG_CALLBACK(void, read_and_copy,
(png_structp png_ptr, png_bytep buffer, png_size_t cb))
(png_structp png_ptr, png_bytep buffer, size_t cb))
{
io_data *io = (io_data*)png_get_io_ptr(png_ptr);

Expand Down Expand Up @@ -100,7 +100,7 @@ static void read_by_row(png_structp png_ptr, png_infop info_ptr,
png_read_info(png_ptr, info_ptr);

{
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);

row = voidcast(png_bytep,malloc(rowbytes));
display = voidcast(png_bytep,malloc(rowbytes));
Expand Down
2 changes: 1 addition & 1 deletion contrib/oss-fuzz/libpng_read_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct PngObjectHandler {
}
};

void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) {
void user_read_data(png_structp png_ptr, png_bytep data, size_t length) {
BufState* buf_state = static_cast<BufState*>(png_get_io_ptr(png_ptr));
if (length > buf_state->bytes_left) {
png_error(png_ptr, "read error");
Expand Down
4 changes: 2 additions & 2 deletions contrib/tools/pngcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ display_start_read(struct display *dp, const char *filename)
}

static void PNGCBAPI
read_function(png_structp pp, png_bytep data, png_size_t size)
read_function(png_structp pp, png_bytep data, size_t size)
{
struct display *dp = get_dp(pp);

Expand Down Expand Up @@ -1881,7 +1881,7 @@ display_start_write(struct display *dp, const char *filename)
}

static void PNGCBAPI
write_function(png_structp pp, png_bytep data, png_size_t size)
write_function(png_structp pp, png_bytep data, size_t size)
{
struct display *dp = get_dp(pp);

Expand Down
Loading

0 comments on commit a74aa9a

Please sign in to comment.