From: Milan Bulat Date: Mon, 29 Jan 2024 03:43:23 +0000 (-0800) Subject: Make the existence of gz_intmax() unconditional. X-Git-Tag: 2.2.0~89 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d2984d0d34e0b4d9426e5d03017b1c4e6795c71;p=thirdparty%2Fzlib-ng.git Make the existence of gz_intmax() unconditional. gz_intmax() is noted in zlib.map. This assures it's always there. madler/zlib#01253ecd7e0a01d311670f2d03c61b82fc12d338 --- diff --git a/gzguts.h b/gzguts.h index a663844b..dc0ebeb2 100644 --- a/gzguts.h +++ b/gzguts.h @@ -139,6 +139,7 @@ void Z_INTERNAL gz_error(gz_state *, int, const char *); /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t value -- needed when comparing unsigned to z_off64_t, which is signed (possible z_off64_t types off_t, off64_t, and long are all signed) */ +unsigned Z_INTERNAL gz_intmax(void); #define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) #endif /* GZGUTS_H_ */ diff --git a/gzlib.c b/gzlib.c index e613837e..8c7a1dc0 100644 --- a/gzlib.c +++ b/gzlib.c @@ -523,3 +523,21 @@ void Z_INTERNAL gz_error(gz_state *state, int err, const char *msg) { } (void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3, "%s%s%s", state->path, ": ", msg); } + +/* portably return maximum value for an int (when limits.h presumed not + available) -- we need to do this to cover cases where 2's complement not + used, since C standard permits 1's complement and sign-bit representations, + otherwise we could just use ((unsigned)-1) >> 1 */ +unsigned Z_INTERNAL gz_intmax(void) { +#ifdef INT_MAX + return INT_MAX; +#else + unsigned p = 1, q; + do { + q = p; + p <<= 1; + p++; + } while (p > q); + return q >> 1; +#endif +}