From 6860c2ea9d7acbdd4dc146b34d0cc46e60846105 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Thu, 5 Apr 2012 11:19:24 +0000 Subject: [PATCH] fix some uint32_t -> size_t typing Change-Id: I078243802a67498dfcd3d15b5f1bebf4b6b3b1bb --- src/dec/idec.c | 18 +++++++++--------- src/dec/webp.c | 17 +++++++++-------- src/dec/webpi.h | 12 +++++++----- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/dec/idec.c b/src/dec/idec.c index 094c26aa..2e010fdf 100644 --- a/src/dec/idec.c +++ b/src/dec/idec.c @@ -51,8 +51,8 @@ typedef enum { // storage for partition #0 and partial data (in a rolling fashion) typedef struct { MemBufferMode mode_; // Operation mode - uint32_t start_; // start location of the data to be decoded - uint32_t end_; // end location + size_t start_; // start location of the data to be decoded + size_t end_; // end location size_t buf_size_; // size of the allocated buffer uint8_t* buf_; // We don't own this buffer in case WebPIUpdate() @@ -69,7 +69,7 @@ struct WebPIDecoder { MemBuffer mem_; // input memory buffer. WebPDecBuffer output_; // output buffer (when no external one is supplied) - uint32_t chunk_size_; // Compressed VP8/VP8L size extracted from Header. + size_t chunk_size_; // Compressed VP8/VP8L size extracted from Header. }; // MB context to restore in case VP8DecodeMB() fails @@ -244,7 +244,7 @@ static VP8StatusCode IDecError(WebPIDecoder* const idec, VP8StatusCode error) { } static void ChangeState(WebPIDecoder* const idec, DecState new_state, - uint32_t consumed_bytes) { + size_t consumed_bytes) { MemBuffer* const mem = &idec->mem_; idec->state_ = new_state; mem->start_ += consumed_bytes; @@ -257,7 +257,7 @@ static void ChangeState(WebPIDecoder* const idec, DecState new_state, static VP8StatusCode DecodeWebPHeaders(WebPIDecoder* const idec) { MemBuffer* const mem = &idec->mem_; const uint8_t* data = mem->buf_ + mem->start_; - uint32_t curr_size = MemDataSize(mem); + size_t curr_size = MemDataSize(mem); VP8StatusCode status; WebPHeaderStructure headers; @@ -270,7 +270,7 @@ static VP8StatusCode DecodeWebPHeaders(WebPIDecoder* const idec) { return IDecError(idec, status); } - idec->chunk_size_ = headers.vp8_size; + idec->chunk_size_ = headers.compressed_size; idec->is_lossless_ = headers.is_lossless; if (!idec->is_lossless_) { VP8Decoder* const dec = VP8New(); @@ -300,7 +300,7 @@ static VP8StatusCode DecodeWebPHeaders(WebPIDecoder* const idec) { static VP8StatusCode DecodeVP8FrameHeader(WebPIDecoder* const idec) { const uint8_t* data = idec->mem_.buf_ + idec->mem_.start_; - const uint32_t curr_size = MemDataSize(&idec->mem_); + const size_t curr_size = MemDataSize(&idec->mem_); uint32_t bits; if (curr_size < VP8_FRAME_HEADER_SIZE) { @@ -455,7 +455,7 @@ static VP8StatusCode DecodeVP8LHeader(WebPIDecoder* const idec) { VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_; const WebPDecParams* const params = &idec->params_; WebPDecBuffer* const output = params->output; - uint32_t curr_size = MemDataSize(&idec->mem_); + size_t curr_size = MemDataSize(&idec->mem_); assert(idec->is_lossless_); // Wait until there's enough data for decoding header. @@ -478,7 +478,7 @@ static VP8StatusCode DecodeVP8LHeader(WebPIDecoder* const idec) { static VP8StatusCode DecodeVP8LData(WebPIDecoder* const idec) { VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_; - const uint32_t curr_size = MemDataSize(&idec->mem_); + const size_t curr_size = MemDataSize(&idec->mem_); assert(idec->is_lossless_); // At present Lossless decoder can't decode image incrementally. So wait till diff --git a/src/dec/webp.c b/src/dec/webp.c index a93c7bb6..09bedbf2 100644 --- a/src/dec/webp.c +++ b/src/dec/webp.c @@ -57,7 +57,7 @@ static WEBP_INLINE uint32_t get_le32(const uint8_t* const data) { // In case there are not enough bytes (partial RIFF container), return 0 for // riff_size. Else return the riff_size extracted from the header. static VP8StatusCode ParseRIFF(const uint8_t** data, uint32_t* data_size, - uint32_t* riff_size) { + size_t* riff_size) { assert(data); assert(data_size); assert(riff_size); @@ -196,8 +196,8 @@ static VP8StatusCode ParseOptionalChunks(const uint8_t** data, // extracted from the VP8/VP8L chunk header. // The flag 'is_lossless' is set to 1 in case of VP8L chunk. static VP8StatusCode ParseVP8Header(const uint8_t** data, uint32_t* data_size, - uint32_t riff_size, - uint32_t* chunk_size, int* is_lossless) { + size_t riff_size, + size_t* chunk_size, int* is_lossless) { const int is_vp8 = !memcmp(*data, "VP8 ", TAG_SIZE); const int is_vp8l = !memcmp(*data, "VP8L", TAG_SIZE); const uint32_t minimal_size = @@ -241,7 +241,7 @@ VP8StatusCode WebPParseHeaders(WebPHeaderStructure* const headers) { buf_size = headers->data_size; headers->alpha_data = NULL; headers->alpha_data_size = 0; - headers->vp8_size = 0; + headers->compressed_size = 0; headers->is_lossless = 0; headers->offset = 0; headers->riff_size = 0; @@ -272,7 +272,7 @@ VP8StatusCode WebPParseHeaders(WebPHeaderStructure* const headers) { // Skip over VP8 chunk header. status = ParseVP8Header(&buf, &buf_size, headers->riff_size, - &headers->vp8_size, &headers->is_lossless); + &headers->compressed_size, &headers->is_lossless); if (status != VP8_STATUS_OK) { return status; // Invalid VP8 header / insufficient data. } @@ -525,8 +525,8 @@ static void DefaultFeatures(WebPBitstreamFeatures* const features) { static VP8StatusCode GetFeatures(const uint8_t* data, uint32_t data_size, WebPBitstreamFeatures* const features) { - uint32_t chunk_size = 0; - uint32_t riff_size = 0; + size_t chunk_size = 0; + size_t riff_size = 0; int* const width = &features->width; int* const height = &features->height; int found_vp8x; @@ -566,7 +566,8 @@ static VP8StatusCode GetFeatures(const uint8_t* data, uint32_t data_size, if (!is_lossless) { // Validates raw VP8 data. - if (!VP8GetInfo(data, data_size, chunk_size, width, height)) { + if (chunk_size != (uint32_t)chunk_size || + !VP8GetInfo(data, data_size, (uint32_t)chunk_size, width, height)) { return VP8_STATUS_BITSTREAM_ERROR; } } else { diff --git a/src/dec/webpi.h b/src/dec/webpi.h index 221cb44c..3f6172af 100644 --- a/src/dec/webpi.h +++ b/src/dec/webpi.h @@ -16,6 +16,8 @@ extern "C" { #endif +#include // for size_t + #include "../webp/decode_vp8.h" #include "../utils/rescaler.h" @@ -58,11 +60,11 @@ void WebPResetDecParams(WebPDecParams* const params); typedef struct { const uint8_t* data; // input buffer uint32_t data_size; // input buffer size - uint32_t offset; // offset to main data chunk (VP8 or VP8L) + size_t offset; // offset to main data chunk (VP8 or VP8L) const uint8_t* alpha_data; // points to alpha chunk (if present) uint32_t alpha_data_size; // alpha chunk size - uint32_t vp8_size; // vp8 compressed data size - uint32_t riff_size; // size of the riff payload (or 0 if absent) + size_t compressed_size; // VP8/VP8L compressed data size + size_t riff_size; // size of the riff payload (or 0 if absent) int is_lossless; // true if a VP8L chunk is present } WebPHeaderStructure; @@ -70,8 +72,8 @@ typedef struct { // Returns VP8_STATUS_OK on success, // VP8_STATUS_BITSTREAM_ERROR if an invalid header/chunk is found, and // VP8_STATUS_NOT_ENOUGH_DATA if case of insufficient data. -// In 'headers', vp8_size, offset, alpha_data, alpha_size and lossless fields -// are updated appropriately upon success. +// In 'headers', compressed_size, offset, alpha_data, alpha_size and lossless +// fields are updated appropriately upon success. VP8StatusCode WebPParseHeaders(WebPHeaderStructure* const headers); //------------------------------------------------------------------------------