diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2012-10-11 16:10:59 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2012-10-11 16:10:59 -0700 |
commit | e69a9ceee0f38e817fc87930ad9792aada3d82fe (patch) | |
tree | ca990a667d85dc35ef9a3a31a6a1db7c2b8bb37b /examples | |
parent | c4888637eaee189c0e21259cb87ab7e5e1d4ce76 (diff) | |
download | zlib-e69a9ceee0f38e817fc87930ad9792aada3d82fe.tar.gz |
Check for input buffer malloc failure in examples/gzappend.c.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/gzappend.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/examples/gzappend.c b/examples/gzappend.c index 0fc42b9..662dec3 100644 --- a/examples/gzappend.c +++ b/examples/gzappend.c @@ -1,7 +1,7 @@ /* gzappend -- command to append to a gzip file Copyright (C) 2003, 2012 Mark Adler, all rights reserved - version 1.2, 13 Aug 2012 + version 1.2, 11 Oct 2012 This software is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages @@ -39,7 +39,8 @@ * - Keep gzip file clean on appended file read errors * - Use in-place rotate instead of auxiliary buffer * (Why you ask? Because it was fun to write!) - * 1.2 13 Aug 2012 - Fix for proper z_const usage + * 1.2 11 Oct 2012 - Fix for proper z_const usage + * - Check for input buffer malloc failure */ /* @@ -400,14 +401,14 @@ local void gztack(char *name, int gd, z_stream *strm, int last) } /* allocate buffers */ - in = fd == -1 ? NULL : malloc(CHUNK); + in = malloc(CHUNK); out = malloc(CHUNK); - if (out == NULL) bye("out of memory", ""); + if (in == NULL || out == NULL) bye("out of memory", ""); /* compress input file and append to gzip file */ do { /* get more input */ - len = fd == -1 ? 0 : read(fd, in, CHUNK); + len = read(fd, in, CHUNK); if (len == -1) { fprintf(stderr, "gzappend warning: error reading %s, skipping rest ...\n", @@ -454,7 +455,7 @@ local void gztack(char *name, int gd, z_stream *strm, int last) /* clean up and return */ free(out); - if (in != NULL) free(in); + free(in); if (fd > 0) close(fd); } @@ -472,7 +473,9 @@ int main(int argc, char **argv) /* provide usage if no arguments */ if (*argv == NULL) { - printf("gzappend 1.1 (4 Nov 2003) Copyright (C) 2003 Mark Adler\n"); + printf( + "gzappend 1.2 (11 Oct 2012) Copyright (C) 2003, 2012 Mark Adler\n" + ); printf( "usage: gzappend [-level] file.gz [ addthis [ andthis ... ]]\n"); return 0; |