]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
[MSVC] Fix size_t/ssize_t when using ZLIB_COMPAT. (#161)
authorMika Lindqvist <postmaster@raasu.org>
Thu, 22 Mar 2018 09:01:18 +0000 (11:01 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 22 Mar 2018 09:01:18 +0000 (10:01 +0100)
* zconf.h.in wasn't including Windows.h, that is correct header to include definitions from BaseTsd.h, and such missing required type definition for ssize_t when compiling using MS Visual C++
* Various places need implicit casting to z_size_t to get around compatibility issues, this will truncate the result when ZLIB_COMPAT is defined, calling code should check for truncation.
* Add ZLIB_COMPAT flag to nmake Makefile and use it to determine correct
  filenames instead of WITH_GZFILEOP

compress.c
test/example.c
uncompr.c
win32/Makefile.msc
zconf.h.in

index b065918672f26d87cfc27445e45e5b753e005731..ce169ef971568b583b0af0412c1f299172d41cef 100644 (file)
@@ -60,7 +60,7 @@ int ZEXPORT PREFIX(compress2)(unsigned char *dest, z_size_t *destLen, const unsi
         err = PREFIX(deflate)(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
     } while (err == Z_OK);
 
-    *destLen = stream.total_out;
+    *destLen = (z_size_t)stream.total_out;
     PREFIX(deflateEnd)(&stream);
     return err == Z_STREAM_END ? Z_OK : err;
 }
index 77c53bfba9f2ee455f28321d5e5c5e94b4adf7dc..4fafc35e46b48d2dc4366aee87cfeb65b42fb11c 100644 (file)
@@ -7,8 +7,10 @@
 
 #ifdef ZLIB_COMPAT
 #  include "zlib.h"
+#  define z_size_t unsigned long
 #else
 #  include "zlib-ng.h"
+#  define z_size_t size_t
 #endif
 
 #include <stdio.h>
@@ -38,7 +40,7 @@ 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_flush         (unsigned char *compr, z_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);
@@ -48,18 +50,18 @@ int  main               (int argc, char *argv[]);
 static alloc_func zalloc = NULL;
 static free_func zfree = NULL;
 
-void test_compress      (unsigned char *compr, size_t comprLen,
-                            unsigned char *uncompr, size_t uncomprLen);
+void test_compress      (unsigned char *compr, z_size_t comprLen,
+                            unsigned char *uncompr, z_size_t uncomprLen);
 
 /* ===========================================================================
  * Test compress() and uncompress()
  */
-void test_compress(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen)
+void test_compress(unsigned char *compr, z_size_t comprLen, unsigned char *uncompr, z_size_t uncomprLen)
 {
     int err;
     size_t len = strlen(hello)+1;
 
-    err = PREFIX(compress)(compr, &comprLen, (const unsigned char*)hello, len);
+    err = PREFIX(compress)(compr, &comprLen, (const unsigned char*)hello, (z_size_t)len);
     CHECK_ERR(err, "compress");
 
     strcpy((char*)uncompr, "garbage");
@@ -77,12 +79,12 @@ void test_compress(unsigned char *compr, size_t comprLen, unsigned char *uncompr
 
 #ifdef WITH_GZFILEOP
 void test_gzio          (const char *fname,
-                            unsigned char *uncompr, size_t uncomprLen);
+                            unsigned char *uncompr, z_size_t uncomprLen);
 
 /* ===========================================================================
  * Test read/write of .gz files
  */
-void test_gzio(const char *fname, unsigned char *uncompr, size_t uncomprLen)
+void test_gzio(const char *fname, unsigned char *uncompr, z_size_t uncomprLen)
 {
 #ifdef NO_GZCOMPRESS
     fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
@@ -332,7 +334,7 @@ void test_large_inflate(unsigned char *compr, size_t comprLen, unsigned char *un
 /* ===========================================================================
  * Test deflate() with full flush
  */
-void test_flush(unsigned char *compr, size_t *comprLen)
+void test_flush(unsigned char *compr, z_size_t *comprLen)
 {
     PREFIX3(stream) c_stream; /* compression stream */
     int err;
@@ -362,7 +364,7 @@ void test_flush(unsigned char *compr, size_t *comprLen)
     err = PREFIX(deflateEnd)(&c_stream);
     CHECK_ERR(err, "deflateEnd");
 
-    *comprLen = c_stream.total_out;
+    *comprLen = (z_size_t)c_stream.total_out;
 }
 
 /* ===========================================================================
@@ -497,8 +499,8 @@ void test_dict_inflate(unsigned char *compr, size_t comprLen, unsigned char *unc
 int main(int argc, char *argv[])
 {
     unsigned char *compr, *uncompr;
-    size_t comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
-    size_t uncomprLen = comprLen;
+    z_size_t comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
+    z_size_t uncomprLen = comprLen;
     static const char* myVersion = PREFIX2(VERSION);
 
     if (zVersion()[0] != myVersion[0]) {
index 68a29cfc46a53230b5d32279a8df028e3a17eadf..77b931ca0da063ddeaa98c0aba3505ca7c09adc6 100644 (file)
--- a/uncompr.c
+++ b/uncompr.c
@@ -73,7 +73,7 @@ int ZEXPORT PREFIX(uncompress2)(unsigned char *dest, z_size_t *destLen, const un
 
     *sourceLen -= len + stream.avail_in;
     if (dest != buf)
-        *destLen = stream.total_out;
+        *destLen = (z_size_t)stream.total_out;
     else if (stream.total_out && err == Z_BUF_ERROR)
         left = 1;
 
index 38c372075f4eb9dc67861d72f31409b1a2528110..08ee855d2ec3ec7c0ac0abc2c002048cd4a275d4 100644 (file)
@@ -31,14 +31,15 @@ DEFFILE = zlib.def
 RCFILE = zlib1.rc
 RESFILE = zlib1.res
 WITH_GZFILEOP =
+ZLIB_COMPAT =
 SUFFIX =
 
 OBJS = adler32.obj compress.obj crc32.obj deflate.obj deflate_fast.obj deflate_quick.obj deflate_slow.obj \
        functable.obj infback.obj inflate.obj inftrees.obj inffast.obj match.obj trees.obj uncompr.obj zutil.obj \
        x86.obj fill_window_sse.obj insert_string_sse.obj crc_folding.obj crc_pclmulqdq.obj
-!if "$(WITH_GZFILEOP)" != ""
-WFLAGS = $(WFLAGS) -DWITH_GZFILEOP
-OBJS = $(OBJS) gzclose.obj gzlib.obj gzread.obj gzwrite.obj
+!if "$(ZLIB_COMPAT)" != ""
+WITH_GZFILEOP = yes
+WFLAGS = $(WFLAGS) -DZLIB_COMPAT
 DEFFILE = zlibcompat.def
 !else
 STATICLIB = zlib-ng.lib
@@ -50,6 +51,11 @@ RESFILE = zlib-ng1.res
 SUFFIX = -ng
 !endif
 
+!if "$(WITH_GZFILEOP)" != ""
+WFLAGS = $(WFLAGS) -DWITH_GZFILEOP
+OBJS = $(OBJS) gzclose.obj gzlib.obj gzread.obj gzwrite.obj
+!endif
+
 # targets
 all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) \
      example.exe minigzip.exe example_d.exe minigzip_d.exe
index 73b204b3302ec95457d20019ed6d26c12b1c5e15..778f54a244f2b9c62d2675934255c7b86be5ce57 100644 (file)
 #    define ZEXPORT WINAPI
 #    define ZEXPORTVA WINAPIV
 #  endif
+#  if defined(_MSC_VER)
+#    include <windows.h>
+     typedef SSIZE_T ssize_t;
+#  endif
 #endif
 
 #ifndef ZEXTERN