Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick compiler compatibility fixes from upstream #63

Merged
merged 5 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions examples/gun.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ local int lunpipe(unsigned have, z_const unsigned char *next, struct ind *indp,
if (last == -1)
return Z_BUF_ERROR;
if (flags & 0x60) {
strm->msg = (char *)"unknown lzw flags set";
strm->msg = (z_const char *)"unknown lzw flags set";
return Z_DATA_ERROR;
}
max = flags & 0x1f;
if (max < 9 || max > 16) {
strm->msg = (char *)"lzw bits out of range";
strm->msg = (z_const char *)"lzw bits out of range";
return Z_DATA_ERROR;
}
if (max == 9) /* 9 doesn't really mean 9 */
Expand All @@ -252,7 +252,7 @@ local int lunpipe(unsigned have, z_const unsigned char *next, struct ind *indp,
if (NEXT() == -1) /* missing a bit */
return Z_BUF_ERROR;
if (last & 1) { /* code must be < 256 */
strm->msg = (char *)"invalid lzw code";
strm->msg = (z_const char *)"invalid lzw code";
return Z_DATA_ERROR;
}
rem = (unsigned)last >> 1; /* remaining 7 bits */
Expand Down Expand Up @@ -319,7 +319,7 @@ local int lunpipe(unsigned have, z_const unsigned char *next, struct ind *indp,
to detect random or corrupted input after a compress header.
In any case, the prev > end check must be retained. */
if (code != end + 1 || prev > end) {
strm->msg = (char *)"invalid lzw code";
strm->msg = (z_const char *)"invalid lzw code";
return Z_DATA_ERROR;
}
match[stack++] = (unsigned char)final;
Expand Down Expand Up @@ -404,7 +404,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
break; /* empty gzip stream is ok */
}
if (last != 31 || (NEXT() != 139 && last != 157)) {
strm->msg = (char *)"incorrect header check";
strm->msg = (z_const char *)"incorrect header check";
ret = first ? Z_DATA_ERROR : Z_ERRNO;
break; /* not a gzip or compress header */
}
Expand All @@ -420,7 +420,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
ret = Z_BUF_ERROR;
if (NEXT() != 8) { /* only deflate method allowed */
if (last == -1) break;
strm->msg = (char *)"unknown compression method";
strm->msg = (z_const char *)"unknown compression method";
ret = Z_DATA_ERROR;
break;
}
Expand All @@ -433,7 +433,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
NEXT();
if (last == -1) break;
if (flags & 0xe0) {
strm->msg = (char *)"unknown header flags set";
strm->msg = (z_const char *)"unknown header flags set";
ret = Z_DATA_ERROR;
break;
}
Expand Down Expand Up @@ -486,7 +486,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
NEXT() != (int)((outd.crc >> 24) & 0xff)) {
/* crc error */
if (last != -1) {
strm->msg = (char *)"incorrect data check";
strm->msg = (z_const char *)"incorrect data check";
ret = Z_DATA_ERROR;
}
break;
Expand All @@ -497,7 +497,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
NEXT() != (int)((outd.total >> 24) & 0xff)) {
/* length error */
if (last != -1) {
strm->msg = (char *)"incorrect length check";
strm->msg = (z_const char *)"incorrect length check";
ret = Z_DATA_ERROR;
}
break;
Expand Down
37 changes: 16 additions & 21 deletions gzguts.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
# include <limits.h>
#endif

#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#ifndef _POSIX_C_SOURCE
# define _POSIX_C_SOURCE 200112L
#endif
#include <fcntl.h>

Expand Down Expand Up @@ -72,33 +72,28 @@
#endif

#ifndef HAVE_VSNPRINTF
# ifdef MSDOS
# if !defined(NO_vsnprintf) && \
(defined(MSDOS) || defined(__TURBOC__) || defined(__SASC) || \
defined(VMS) || defined(__OS400) || defined(__MVS__))
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
but for now we just assume it doesn't. */
# define NO_vsnprintf
# endif
# ifdef __TURBOC__
# define NO_vsnprintf
# endif
# ifdef WIN32
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
# define vsnprintf _vsnprintf
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
# ifndef vsnprintf
# define vsnprintf _vsnprintf
# endif
# endif
# endif
# ifdef __SASC
# define NO_vsnprintf
# endif
# ifdef VMS
# define NO_vsnprintf
# endif
# ifdef __OS400__
# define NO_vsnprintf
# endif
# ifdef __MVS__
# define NO_vsnprintf
# elif !defined(__STDC_VERSION__) || __STDC_VERSION__-0 < 199901L
/* Otherwise if C89/90, assume no C99 snprintf() or vsnprintf() */
# ifndef NO_snprintf
# define NO_snprintf
# endif
# ifndef NO_vsnprintf
# define NO_vsnprintf
# endif
# endif
#endif

Expand Down
24 changes: 12 additions & 12 deletions infback.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
state->mode = TABLE;
break;
case 3:
strm->msg = (char *)"invalid block type";
strm->msg = (z_const char *)"invalid block type";
state->mode = BAD;
}
DROPBITS(2);
Expand All @@ -318,7 +318,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
BYTEBITS(); /* go to byte boundary */
NEEDBITS(32);
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
strm->msg = (char *)"invalid stored block lengths";
strm->msg = (z_const char *)"invalid stored block lengths";
state->mode = BAD;
break;
}
Expand Down Expand Up @@ -356,7 +356,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
DROPBITS(4);
#ifndef PKZIP_BUG_WORKAROUND
if (state->nlen > 286 || state->ndist > 30) {
strm->msg = (char *)"too many length or distance symbols";
strm->msg = (z_const char *)"too many length or distance symbols";
state->mode = BAD;
break;
}
Expand All @@ -378,7 +378,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
ret = inflate_table(CODES, state->lens, 19, &(state->next),
&(state->lenbits), state->work);
if (ret) {
strm->msg = (char *)"invalid code lengths set";
strm->msg = (z_const char *)"invalid code lengths set";
state->mode = BAD;
break;
}
Expand All @@ -401,7 +401,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
NEEDBITS(here.bits + 2);
DROPBITS(here.bits);
if (state->have == 0) {
strm->msg = (char *)"invalid bit length repeat";
strm->msg = (z_const char *)"invalid bit length repeat";
state->mode = BAD;
break;
}
Expand All @@ -424,7 +424,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
DROPBITS(7);
}
if (state->have + copy > state->nlen + state->ndist) {
strm->msg = (char *)"invalid bit length repeat";
strm->msg = (z_const char *)"invalid bit length repeat";
state->mode = BAD;
break;
}
Expand All @@ -438,7 +438,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,

/* check for end-of-block code (better have one) */
if (state->lens[256] == 0) {
strm->msg = (char *)"invalid code -- missing end-of-block";
strm->msg = (z_const char *)"invalid code -- missing end-of-block";
state->mode = BAD;
break;
}
Expand All @@ -452,7 +452,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
&(state->lenbits), state->work);
if (ret) {
strm->msg = (char *)"invalid literal/lengths set";
strm->msg = (z_const char *)"invalid literal/lengths set";
state->mode = BAD;
break;
}
Expand All @@ -461,7 +461,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
&(state->next), &(state->distbits), state->work);
if (ret) {
strm->msg = (char *)"invalid distances set";
strm->msg = (z_const char *)"invalid distances set";
state->mode = BAD;
break;
}
Expand Down Expand Up @@ -521,7 +521,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,

/* invalid code */
if (here.op & 64) {
strm->msg = (char *)"invalid literal/length code";
strm->msg = (z_const char *)"invalid literal/length code";
state->mode = BAD;
break;
}
Expand Down Expand Up @@ -553,7 +553,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
}
DROPBITS(here.bits);
if (here.op & 64) {
strm->msg = (char *)"invalid distance code";
strm->msg = (z_const char *)"invalid distance code";
state->mode = BAD;
break;
}
Expand All @@ -568,7 +568,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
}
if (state->offset > state->wsize - (state->whave < state->wsize ?
left : 0)) {
strm->msg = (char *)"invalid distance too far back";
strm->msg = (z_const char *)"invalid distance too far back";
state->mode = BAD;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions inffast.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
dist += (unsigned)hold & ((1U << op) - 1);
#ifdef INFLATE_STRICT
if (dist > dmax) {
strm->msg = (char *)"invalid distance too far back";
strm->msg = (z_const char *)"invalid distance too far back";
state->mode = BAD;
break;
}
Expand All @@ -167,7 +167,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
if (op > whave) {
if (state->sane) {
strm->msg =
(char *)"invalid distance too far back";
(z_const char *)"invalid distance too far back";
state->mode = BAD;
break;
}
Expand Down Expand Up @@ -263,7 +263,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
goto dodist;
}
else {
strm->msg = (char *)"invalid distance code";
strm->msg = (z_const char *)"invalid distance code";
state->mode = BAD;
break;
}
Expand All @@ -278,7 +278,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
break;
}
else {
strm->msg = (char *)"invalid literal/length code";
strm->msg = (z_const char *)"invalid literal/length code";
state->mode = BAD;
break;
}
Expand Down
Loading