diff options
Diffstat (limited to 'zlibWrapper')
| -rw-r--r-- | zlibWrapper/examples/minigzip.c | 18 | ||||
| -rw-r--r-- | zlibWrapper/examples/zwrapbench.c | 6 | ||||
| -rw-r--r-- | zlibWrapper/gzguts.h | 4 | ||||
| -rw-r--r-- | zlibWrapper/gzlib.c | 4 | ||||
| -rw-r--r-- | zlibWrapper/gzwrite.c | 9 |
5 files changed, 15 insertions, 26 deletions
diff --git a/zlibWrapper/examples/minigzip.c b/zlibWrapper/examples/minigzip.c index 521d047117c51..f67be09564f25 100644 --- a/zlibWrapper/examples/minigzip.c +++ b/zlibWrapper/examples/minigzip.c @@ -18,6 +18,8 @@ /* @(#) $Id$ */ +#define _POSIX_SOURCE /* fileno */ + #include "zstd_zlibwrapper.h" #include <stdio.h> @@ -470,12 +472,8 @@ void file_compress(file, mode) exit(1); } -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(outfile, sizeof(outfile), "%s%s", file, GZ_SUFFIX); -#else strcpy(outfile, file); strcat(outfile, GZ_SUFFIX); -#endif in = fopen(file, "rb"); if (in == NULL) { @@ -510,11 +508,7 @@ void file_uncompress(file) exit(1); } -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(buf, sizeof(buf), "%s", file); -#else strcpy(buf, file); -#endif if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) { infile = file; @@ -523,11 +517,7 @@ void file_uncompress(file) } else { outfile = file; infile = buf; -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(buf + len, sizeof(buf) - len, "%s", GZ_SUFFIX); -#else strcat(infile, GZ_SUFFIX); -#endif } in = gzopen(infile, "rb"); if (in == NULL) { @@ -565,11 +555,7 @@ int main(argc, argv) gzFile file; char *bname, outmode[20]; -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(outmode, sizeof(outmode), "%s", "wb6 "); -#else strcpy(outmode, "wb6 "); -#endif prog = argv[0]; bname = strrchr(argv[0], '/'); diff --git a/zlibWrapper/examples/zwrapbench.c b/zlibWrapper/examples/zwrapbench.c index a4dfbb6e8c47e..d2d6073f9c0e7 100644 --- a/zlibWrapper/examples/zwrapbench.c +++ b/zlibWrapper/examples/zwrapbench.c @@ -573,10 +573,10 @@ static size_t BMK_findMaxMem(U64 requiredMem) do { testmem = (BYTE*)malloc((size_t)requiredMem); requiredMem -= step; - } while (!testmem); + } while (!testmem && requiredMem); /* do not allocate zero bytes */ free(testmem); - return (size_t)(requiredMem); + return (size_t)(requiredMem+1); /* avoid zero */ } static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize, @@ -734,7 +734,7 @@ static void BMK_benchFileTable(const char** fileNamesTable, unsigned nbFiles, if ((U64)benchedSize > totalSizeToLoad) benchedSize = (size_t)totalSizeToLoad; if (benchedSize < totalSizeToLoad) DISPLAY("Not enough memory; testing %u MB only...\n", (U32)(benchedSize >> 20)); - srcBuffer = malloc(benchedSize); + srcBuffer = malloc(benchedSize + !benchedSize); if (!srcBuffer) EXM_THROW(12, "not enough memory"); /* Load input buffer */ diff --git a/zlibWrapper/gzguts.h b/zlibWrapper/gzguts.h index 84651b88d389e..05bf4d9f4c31c 100644 --- a/zlibWrapper/gzguts.h +++ b/zlibWrapper/gzguts.h @@ -1,5 +1,5 @@ /* gzguts.h contains minimal changes required to be compiled with zlibWrapper: - * - #include "zlib.h" was changed to #include "zstd_zlibwrapper.h" + * - #include "zlib.h" was changed to #include "zstd_zlibwrapper.h" * - gz_statep was converted to union to work with -Wstrict-aliasing=1 */ /* gzguts.h -- zlib internal header definitions for gz* operations @@ -44,7 +44,7 @@ # include <io.h> #endif -#if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) # define WIDECHAR #endif diff --git a/zlibWrapper/gzlib.c b/zlibWrapper/gzlib.c index 8235cff4fda14..3070dd8b4975c 100644 --- a/zlibWrapper/gzlib.c +++ b/zlibWrapper/gzlib.c @@ -111,7 +111,7 @@ local gzFile gz_open(path, fd, mode) return NULL; /* allocate gzFile structure to return */ - state = (gz_statep)(gz_state*)malloc(sizeof(gz_state)); + state.state = (gz_state*)malloc(sizeof(gz_state)); if (state.state == NULL) return NULL; state.state->size = 0; /* no buffers allocated yet */ @@ -266,7 +266,7 @@ local gzFile gz_open(path, fd, mode) gz_reset(state); /* return stream */ - return (gzFile)state.file; + return state.file; } /* -- see zlib.h -- */ diff --git a/zlibWrapper/gzwrite.c b/zlibWrapper/gzwrite.c index d1250b90084da..21d5f84727aae 100644 --- a/zlibWrapper/gzwrite.c +++ b/zlibWrapper/gzwrite.c @@ -6,6 +6,8 @@ * For conditions of distribution and use, see http://www.zlib.net/zlib_license.html */ +#include <assert.h> + #include "gzguts.h" /* Local functions */ @@ -24,7 +26,7 @@ local int gz_init(state) z_streamp strm = &(state.state->strm); /* allocate input buffer (double size for gzprintf) */ - state.state->in = (unsigned char *)malloc(state.state->want << 1); + state.state->in = (unsigned char*)malloc(state.state->want << 1); if (state.state->in == NULL) { gz_error(state, Z_MEM_ERROR, "out of memory"); return -1; @@ -33,7 +35,7 @@ local int gz_init(state) /* only need output buffer and deflate state if compressing */ if (!state.state->direct) { /* allocate output buffer */ - state.state->out = (unsigned char *)malloc(state.state->want); + state.state->out = (unsigned char*)malloc(state.state->want); if (state.state->out == NULL) { free(state.state->in); gz_error(state, Z_MEM_ERROR, "out of memory"); @@ -284,6 +286,7 @@ z_size_t ZEXPORT gzfwrite(buf, size, nitems, file) gz_statep state; /* get internal structure */ + assert(size != 0); if (file == NULL) return 0; state = (gz_statep)file; @@ -294,7 +297,7 @@ z_size_t ZEXPORT gzfwrite(buf, size, nitems, file) /* compute bytes to read -- error on overflow */ len = nitems * size; - if (size && len / size != nitems) { + if (size && (len / size != nitems)) { gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t"); return 0; } |
