]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Simplify version and struct size checking, and ensure we do it the same way everywhere.
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Fri, 11 Feb 2022 11:08:43 +0000 (12:08 +0100)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 3 Jun 2022 08:21:01 +0000 (10:21 +0200)
deflate.c
infback.c
inflate.c
zutil.h

index 369b17b5bbd559bfb0980662f860d36783bfd143..878033355cf3fa974c340bed4a463c6522618e20 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -325,18 +325,16 @@ int32_t Z_EXPORT PREFIX(deflateInit)(PREFIX3(stream) *strm, int32_t level) {
 
 /* Function used by zlib.h and zlib-ng version 2.0 macros */
 int32_t Z_EXPORT PREFIX(deflateInit_)(PREFIX3(stream) *strm, int32_t level, const char *version, int32_t stream_size) {
-    if (version == NULL || version[0] != PREFIX2(VERSION)[0] || stream_size != sizeof(PREFIX3(stream))) {
+    if (CHECK_VER_STSIZE(version, stream_size))
         return Z_VERSION_ERROR;
-    }
     return PREFIX(deflateInit2)(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
 }
 
 /* Function used by zlib.h and zlib-ng version 2.0 macros */
 int32_t Z_EXPORT PREFIX(deflateInit2_)(PREFIX3(stream) *strm, int32_t level, int32_t method, int32_t windowBits,
                            int32_t memLevel, int32_t strategy, const char *version, int32_t stream_size) {
-    if (version == NULL || version[0] != PREFIX2(VERSION)[0] || stream_size != sizeof(PREFIX3(stream))) {
+    if (CHECK_VER_STSIZE(version, stream_size))
         return Z_VERSION_ERROR;
-    }
     return PREFIX(deflateInit2)(strm, level, method, windowBits, memLevel, strategy);
 }
 
index 80024257217871e02a5221311b5668a925f60938..dd549a89fb61525d0247d3cb3aea9f2081873d23 100644 (file)
--- a/infback.c
+++ b/infback.c
@@ -62,9 +62,8 @@ int32_t ZNG_CONDEXPORT PREFIX(inflateBackInit)(PREFIX3(stream) *strm, int32_t wi
 /* Function used by zlib.h and zlib-ng version 2.0 macros */
 int32_t Z_EXPORT PREFIX(inflateBackInit_)(PREFIX3(stream) *strm, int32_t windowBits, uint8_t *window,
                               const char *version, int32_t stream_size) {
-    if (version == NULL || version[0] != PREFIX2(VERSION)[0] || stream_size != (int)(sizeof(PREFIX3(stream)))) {
+    if (CHECK_VER_STSIZE(version, stream_size))
         return Z_VERSION_ERROR;
-    }
     return PREFIX(inflateBackInit)(strm, windowBits, window);
 }
 
index 68531ab9aa384015d13f84bb625318f49ac09e3d..6192148233d593387a6bed5e27766a060a02965d 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -175,14 +175,14 @@ int32_t Z_EXPORT PREFIX(inflateInit)(PREFIX3(stream) *strm) {
 
 /* Function used by zlib.h and zlib-ng version 2.0 macros */
 int32_t Z_EXPORT PREFIX(inflateInit_)(PREFIX3(stream) *strm, const char *version, int32_t stream_size) {
-    if (version == NULL || version[0] != PREFIX2(VERSION)[0] || stream_size != (int)(sizeof(PREFIX3(stream))))
+    if (CHECK_VER_STSIZE(version, stream_size))
         return Z_VERSION_ERROR;
     return PREFIX(inflateInit2)(strm, DEF_WBITS);
 }
 
 /* Function used by zlib.h and zlib-ng version 2.0 macros */
 int32_t Z_EXPORT PREFIX(inflateInit2_)(PREFIX3(stream) *strm, int32_t windowBits, const char *version, int32_t stream_size) {
-    if (version == NULL || version[0] != PREFIX2(VERSION)[0] || stream_size != (int)(sizeof(PREFIX3(stream))))
+    if (CHECK_VER_STSIZE(version, stream_size))
         return Z_VERSION_ERROR;
     return PREFIX(inflateInit2)(strm, windowBits);
 }
diff --git a/zutil.h b/zutil.h
index f70eb4bdbbfa4466a4e484a80b6df6fcfbd1ace3..53c7cdf148e7e4e46e3d27b26b7467dbbec9c9c5 100644 (file)
--- a/zutil.h
+++ b/zutil.h
@@ -120,6 +120,10 @@ extern z_const char * const PREFIX(z_errmsg)[10]; /* indexed by 2-zlib_error */
 #  define OS_CODE  3  /* assume Unix */
 #endif
 
+         /* macros */
+
+#define CHECK_VER_STSIZE(_ver,_stsize) ((_ver) == NULL || (_ver)[0] != PREFIX2(VERSION)[0] || (_stsize) != (int32_t)sizeof(PREFIX3(stream)))
+
          /* memory allocation functions */
 
 void Z_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size);