From: Mika Lindqvist Date: Sat, 21 Nov 2015 14:53:40 +0000 (+0200) Subject: Use size_t for total_in and total_out. X-Git-Tag: 1.9.9-b1~790^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F60%2Fhead;p=thirdparty%2Fzlib-ng.git Use size_t for total_in and total_out. --- diff --git a/compress.c b/compress.c index 7c823abf..9f6f1402 100644 --- a/compress.c +++ b/compress.c @@ -19,12 +19,12 @@ memory, Z_BUF_ERROR if there was not enough room in the output buffer, Z_STREAM_ERROR if the level parameter is invalid. */ -int ZEXPORT compress2(unsigned char *dest, unsigned long *destLen, const unsigned char *source, - unsigned long sourceLen, int level) { +int ZEXPORT compress2(unsigned char *dest, size_t *destLen, const unsigned char *source, + size_t sourceLen, int level) { z_stream stream; int err; const unsigned int max = (unsigned int)0 - 1; - unsigned long left; + size_t left; left = *destLen; *destLen = 0; @@ -61,7 +61,7 @@ int ZEXPORT compress2(unsigned char *dest, unsigned long *destLen, const unsigne /* =========================================================================== */ -int ZEXPORT compress(unsigned char *dest, unsigned long *destLen, const unsigned char *source, unsigned long sourceLen) { +int ZEXPORT compress(unsigned char *dest, size_t *destLen, const unsigned char *source, size_t sourceLen) { return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); } @@ -69,6 +69,6 @@ int ZEXPORT compress(unsigned char *dest, unsigned long *destLen, const unsigned If the default memLevel or windowBits for deflateInit() is changed, then this function needs to be updated. */ -unsigned long ZEXPORT compressBound(unsigned long sourceLen) { +size_t ZEXPORT compressBound(size_t sourceLen) { return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13; } diff --git a/inflate.c b/inflate.c index 3415aeeb..8d4a992f 100644 --- a/inflate.c +++ b/inflate.c @@ -1337,7 +1337,7 @@ local unsigned syncsearch(uint32_t *have, const unsigned char *buf, uint32_t len int ZEXPORT inflateSync(z_stream *strm) { unsigned len; /* number of bytes to look at or looked at */ - unsigned long in, out; /* temporary to save total_in and total_out */ + size_t in, out; /* temporary to save total_in and total_out */ unsigned char buf[4]; /* to restore bit buffer to byte string */ struct inflate_state *state; diff --git a/test/example.c b/test/example.c index eaf45014..43d1a16c 100644 --- a/test/example.c +++ b/test/example.c @@ -29,30 +29,30 @@ const char hello[] = "hello, hello!"; const char dictionary[] = "hello"; unsigned long dictId; /* Adler32 value of the dictionary */ -void test_deflate (unsigned char *compr, unsigned long comprLen); -void test_inflate (unsigned char *compr, unsigned long comprLen, unsigned char *uncompr, unsigned long uncomprLen); -void test_large_deflate (unsigned char *compr, unsigned long comprLen, unsigned char *uncompr, unsigned long uncomprLen); -void test_large_inflate (unsigned char *compr, unsigned long comprLen, unsigned char *uncompr, unsigned long uncomprLen); -void test_flush (unsigned char *compr, unsigned long *comprLen); -void test_sync (unsigned char *compr, unsigned long comprLen, unsigned char *uncompr, unsigned long uncomprLen); -void test_dict_deflate (unsigned char *compr, unsigned long comprLen); -void test_dict_inflate (unsigned char *compr, unsigned long comprLen, unsigned char *uncompr, unsigned long uncomprLen); +void test_deflate (unsigned char *compr, size_t comprLen); +void test_inflate (unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen); +void test_large_deflate (unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen); +void test_large_inflate (unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen); +void test_flush (unsigned char *compr, size_t *comprLen); +void test_sync (unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen); +void test_dict_deflate (unsigned char *compr, size_t comprLen); +void test_dict_inflate (unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen); int main (int argc, char *argv[]); static alloc_func zalloc = (alloc_func)0; static free_func zfree = (free_func)0; -void test_compress (unsigned char *compr, unsigned long comprLen, - unsigned char *uncompr, unsigned long uncomprLen); +void test_compress (unsigned char *compr, size_t comprLen, + unsigned char *uncompr, size_t uncomprLen); /* =========================================================================== * Test compress() and uncompress() */ -void test_compress(unsigned char *compr, unsigned long comprLen, unsigned char *uncompr, unsigned long uncomprLen) +void test_compress(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) { int err; - unsigned long len = (unsigned long)strlen(hello)+1; + size_t len = strlen(hello)+1; err = compress(compr, &comprLen, (const unsigned char*)hello, len); CHECK_ERR(err, "compress"); @@ -160,7 +160,7 @@ void test_gzio(const char *fname, unsigned char *uncompr, unsigned long uncomprL /* =========================================================================== * Test deflate() with small buffers */ -void test_deflate(unsigned char *compr, unsigned long comprLen) +void test_deflate(unsigned char *compr, size_t comprLen) { z_stream c_stream; /* compression stream */ int err; @@ -196,7 +196,7 @@ void test_deflate(unsigned char *compr, unsigned long comprLen) /* =========================================================================== * Test inflate() with small buffers */ -void test_inflate(unsigned char *compr, unsigned long comprLen, unsigned char *uncompr, unsigned long uncomprLen) +void test_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) { int err; z_stream d_stream; /* decompression stream */ @@ -235,7 +235,7 @@ void test_inflate(unsigned char *compr, unsigned long comprLen, unsigned char *u /* =========================================================================== * Test deflate() with large buffers and dynamic change of compression level */ -void test_large_deflate(unsigned char *compr, unsigned long comprLen, unsigned char *uncompr, unsigned long uncomprLen) +void test_large_deflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) { z_stream c_stream; /* compression stream */ int err; @@ -288,7 +288,7 @@ void test_large_deflate(unsigned char *compr, unsigned long comprLen, unsigned c /* =========================================================================== * Test inflate() with large buffers */ -void test_large_inflate(unsigned char *compr, unsigned long comprLen, unsigned char *uncompr, unsigned long uncomprLen) +void test_large_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) { int err; z_stream d_stream; /* decompression stream */ @@ -317,7 +317,7 @@ void test_large_inflate(unsigned char *compr, unsigned long comprLen, unsigned c CHECK_ERR(err, "inflateEnd"); if (d_stream.total_out != 2*uncomprLen + comprLen/2) { - fprintf(stderr, "bad large inflate: %" PRId32 "\n", d_stream.total_out); + fprintf(stderr, "bad large inflate: %zu\n", d_stream.total_out); exit(1); } else { printf("large_inflate(): OK\n"); @@ -327,7 +327,7 @@ void test_large_inflate(unsigned char *compr, unsigned long comprLen, unsigned c /* =========================================================================== * Test deflate() with full flush */ -void test_flush(unsigned char *compr, unsigned long *comprLen) +void test_flush(unsigned char *compr, size_t *comprLen) { z_stream c_stream; /* compression stream */ int err; @@ -363,7 +363,7 @@ void test_flush(unsigned char *compr, unsigned long *comprLen) /* =========================================================================== * Test inflateSync() */ -void test_sync(unsigned char *compr, unsigned long comprLen, unsigned char *uncompr, unsigned long uncomprLen) +void test_sync(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) { int err; z_stream d_stream; /* decompression stream */ @@ -405,7 +405,7 @@ void test_sync(unsigned char *compr, unsigned long comprLen, unsigned char *unco /* =========================================================================== * Test deflate() with preset dictionary */ -void test_dict_deflate(unsigned char *compr, unsigned long comprLen) +void test_dict_deflate(unsigned char *compr, size_t comprLen) { z_stream c_stream; /* compression stream */ int err; @@ -440,7 +440,7 @@ void test_dict_deflate(unsigned char *compr, unsigned long comprLen) /* =========================================================================== * Test inflate() with a preset dictionary */ -void test_dict_inflate(unsigned char *compr, unsigned long comprLen, unsigned char *uncompr, unsigned long uncomprLen) +void test_dict_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) { int err; z_stream d_stream; /* decompression stream */ @@ -492,8 +492,8 @@ void test_dict_inflate(unsigned char *compr, unsigned long comprLen, unsigned ch int main(int argc, char *argv[]) { unsigned char *compr, *uncompr; - unsigned long comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */ - unsigned long uncomprLen = comprLen; + size_t comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */ + size_t uncomprLen = comprLen; static const char* myVersion = ZLIB_VERSION; if (zlibVersion()[0] != myVersion[0]) { diff --git a/uncompr.c b/uncompr.c index a195cdcf..c2af140d 100644 --- a/uncompr.c +++ b/uncompr.c @@ -22,11 +22,11 @@ buffer, or Z_DATA_ERROR if the input data was corrupted, including if the input data is an incomplete zlib stream. */ -int ZEXPORT uncompress(unsigned char *dest, unsigned long *destLen, const unsigned char *source, unsigned long sourceLen) { +int ZEXPORT uncompress(unsigned char *dest, size_t *destLen, const unsigned char *source, size_t sourceLen) { z_stream stream; int err; const unsigned int max = (unsigned int)0 - 1; - unsigned long left; + size_t left; unsigned char buf[1]; /* for detection of incomplete stream when *destLen == 0 */ if (*destLen) { diff --git a/zlib.h b/zlib.h index 57087793..3a1cbb2f 100644 --- a/zlib.h +++ b/zlib.h @@ -92,11 +92,11 @@ struct internal_state; typedef struct z_stream_s { const unsigned char *next_in; /* next input byte */ uint32_t avail_in; /* number of bytes available at next_in */ - uint32_t total_in; /* total number of input bytes read so far */ + size_t total_in; /* total number of input bytes read so far */ unsigned char *next_out; /* next output byte should be put there */ uint32_t avail_out; /* remaining free space at next_out */ - uint32_t total_out; /* total number of bytes output so far */ + size_t total_out; /* total number of bytes output so far */ const char *msg; /* last error message, NULL if no error */ struct internal_state *state; /* not visible by applications */ @@ -1148,7 +1148,7 @@ ZEXTERN unsigned long ZEXPORT zlibCompileFlags(void); you need special options. */ -ZEXTERN int ZEXPORT compress(unsigned char *dest, unsigned long *destLen, const unsigned char *source, unsigned long sourceLen); +ZEXTERN int ZEXPORT compress(unsigned char *dest, size_t *destLen, const unsigned char *source, size_t sourceLen); /* Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1162,8 +1162,8 @@ ZEXTERN int ZEXPORT compress(unsigned char *dest, unsigned long *destLen, const buffer. */ -ZEXTERN int ZEXPORT compress2(unsigned char *dest, unsigned long *destLen, const unsigned char *source, - unsigned long sourceLen, int level); +ZEXTERN int ZEXPORT compress2(unsigned char *dest, size_t *destLen, const unsigned char *source, + size_t sourceLen, int level); /* Compresses the source buffer into the destination buffer. The level parameter has the same meaning as in deflateInit. sourceLen is the byte @@ -1177,14 +1177,14 @@ ZEXTERN int ZEXPORT compress2(unsigned char *dest, unsigned long *destLen, const Z_STREAM_ERROR if the level parameter is invalid. */ -ZEXTERN unsigned long ZEXPORT compressBound(unsigned long sourceLen); +ZEXTERN size_t ZEXPORT compressBound(size_t sourceLen); /* compressBound() returns an upper bound on the compressed size after compress() or compress2() on sourceLen bytes. It would be used before a compress() or compress2() call to allocate the destination buffer. */ -ZEXTERN int ZEXPORT uncompress(unsigned char *dest, unsigned long *destLen, const unsigned char *source, unsigned long sourceLen); +ZEXTERN int ZEXPORT uncompress(unsigned char *dest, size_t *destLen, const unsigned char *source, size_t sourceLen); /* Decompresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size