]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Use size_t for total_in and total_out. 60/head
authorMika Lindqvist <postmaster@raasu.org>
Sat, 21 Nov 2015 14:53:40 +0000 (16:53 +0200)
committerMika Lindqvist <postmaster@raasu.org>
Mon, 14 Dec 2015 09:00:31 +0000 (11:00 +0200)
compress.c
inflate.c
test/example.c
uncompr.c
zlib.h

index 7c823abfde074a2b530d7e4898c10198536ff526..9f6f140298fc9898b8adb1704a839a499f2f5374 100644 (file)
    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;
 }
index 3415aeeb02ef84fdc61eb2f87cc126f046b44cbe..8d4a992f957690b8a6f109f3c87c1ed7e69c96a5 100644 (file)
--- 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;
 
index eaf45014469060534aa9e12f359523f2f583e767..43d1a16cbe0a0291f710f5c67e4312889aef6ea3 100644 (file)
@@ -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]) {
index a195cdcf70243fae1f056ae0fc7fd2c8f98d145d..c2af140db1e1f29a8f1af7f5c1529637299f750a 100644 (file)
--- a/uncompr.c
+++ b/uncompr.c
    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 57087793fb652ef95a709fb5609bcccbdf2f8e8a..3a1cbb2f05b001791f8ae8a5900c40be75ed4b27 100644 (file)
--- 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