Skip to content

Commit

Permalink
Use z_const for setting msg to literal strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lwisce Zeng authored and madler committed Apr 1, 2024
1 parent c5e87dc commit 2ba25b2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 58 deletions.
24 changes: 12 additions & 12 deletions contrib/infback9/infback9.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ int ZEXPORT inflateBack9(z_stream FAR *strm, in_func in, void FAR *in_desc,
mode = TABLE;
break;
case 3:
strm->msg = (char *)"invalid block type";
strm->msg = (z_const char *)"invalid block type";
mode = BAD;
}
DROPBITS(2);
Expand All @@ -304,7 +304,7 @@ int ZEXPORT inflateBack9(z_stream FAR *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";
mode = BAD;
break;
}
Expand Down Expand Up @@ -341,7 +341,7 @@ int ZEXPORT inflateBack9(z_stream FAR *strm, in_func in, void FAR *in_desc,
state->ncode = BITS(4) + 4;
DROPBITS(4);
if (state->nlen > 286) {
strm->msg = (char *)"too many length symbols";
strm->msg = (z_const char *)"too many length symbols";
mode = BAD;
break;
}
Expand All @@ -362,7 +362,7 @@ int ZEXPORT inflateBack9(z_stream FAR *strm, in_func in, void FAR *in_desc,
ret = inflate_table9(CODES, state->lens, 19, &(state->next),
&(lenbits), state->work);
if (ret) {
strm->msg = (char *)"invalid code lengths set";
strm->msg = (z_const char *)"invalid code lengths set";
mode = BAD;
break;
}
Expand All @@ -386,7 +386,7 @@ int ZEXPORT inflateBack9(z_stream FAR *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";
mode = BAD;
break;
}
Expand All @@ -409,7 +409,7 @@ int ZEXPORT inflateBack9(z_stream FAR *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";
mode = BAD;
break;
}
Expand All @@ -423,7 +423,7 @@ int ZEXPORT inflateBack9(z_stream FAR *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";
mode = BAD;
break;
}
Expand All @@ -437,7 +437,7 @@ int ZEXPORT inflateBack9(z_stream FAR *strm, in_func in, void FAR *in_desc,
ret = inflate_table9(LENS, state->lens, state->nlen,
&(state->next), &(lenbits), state->work);
if (ret) {
strm->msg = (char *)"invalid literal/lengths set";
strm->msg = (z_const char *)"invalid literal/lengths set";
mode = BAD;
break;
}
Expand All @@ -447,7 +447,7 @@ int ZEXPORT inflateBack9(z_stream FAR *strm, in_func in, void FAR *in_desc,
state->ndist, &(state->next), &(distbits),
state->work);
if (ret) {
strm->msg = (char *)"invalid distances set";
strm->msg = (z_const char *)"invalid distances set";
mode = BAD;
break;
}
Expand Down Expand Up @@ -495,7 +495,7 @@ int ZEXPORT inflateBack9(z_stream FAR *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";
mode = BAD;
break;
}
Expand Down Expand Up @@ -527,7 +527,7 @@ int ZEXPORT inflateBack9(z_stream FAR *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";
mode = BAD;
break;
}
Expand All @@ -541,7 +541,7 @@ int ZEXPORT inflateBack9(z_stream FAR *strm, in_func in, void FAR *in_desc,
DROPBITS(extra);
}
if (offset > WSIZE - (wrap ? 0: left)) {
strm->msg = (char *)"invalid distance too far back";
strm->msg = (z_const char *)"invalid distance too far back";
mode = BAD;
break;
}
Expand Down
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
24 changes: 12 additions & 12 deletions infback.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,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 @@ -315,7 +315,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 @@ -353,7 +353,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 @@ -375,7 +375,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 @@ -398,7 +398,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 @@ -421,7 +421,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 @@ -435,7 +435,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 @@ -449,7 +449,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 @@ -458,7 +458,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 @@ -517,7 +517,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 @@ -549,7 +549,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 @@ -564,7 +564,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 @@ -155,7 +155,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 @@ -169,7 +169,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 @@ -265,7 +265,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 @@ -280,7 +280,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

0 comments on commit 2ba25b2

Please sign in to comment.