diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2024-02-02 13:39:10 -0800 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2024-02-04 18:48:30 -0800 |
commit | be4db0a79add326bf06ff46b550f564288749f90 (patch) | |
tree | e0b89cf21a370b9a08f6abcbed6899ed4b880b7a /examples/zran.c | |
parent | f1f503da85d52e56aae11557b4d79a42bcaa2b86 (diff) | |
download | zlib-be4db0a79add326bf06ff46b550f564288749f90.tar.gz zlib-be4db0a79add326bf06ff46b550f564288749f90.tar.bz2 zlib-be4db0a79add326bf06ff46b550f564288749f90.zip |
Set returned index to NULL on an index build error in zran.c.
An attempt to use the returned pointer in deflate_index_extract()
will now return cleanly with an error. The returned pointer can
now also be used with deflate_index_free() even on error.
Diffstat (limited to 'examples/zran.c')
-rw-r--r-- | examples/zran.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/examples/zran.c b/examples/zran.c index d313595..9c3e5dc 100644 --- a/examples/zran.c +++ b/examples/zran.c | |||
@@ -130,6 +130,10 @@ static struct deflate_index *add_point(struct deflate_index *index, int bits, | |||
130 | 130 | ||
131 | // See comments in zran.h. | 131 | // See comments in zran.h. |
132 | int deflate_index_build(FILE *in, off_t span, struct deflate_index **built) { | 132 | int deflate_index_build(FILE *in, off_t span, struct deflate_index **built) { |
133 | // If this returns with an error, any attempt to use the index will cleanly | ||
134 | // return an error. | ||
135 | *built = NULL; | ||
136 | |||
133 | // Set up inflation state. | 137 | // Set up inflation state. |
134 | z_stream strm = {0}; // inflate engine (gets fired up later) | 138 | z_stream strm = {0}; // inflate engine (gets fired up later) |
135 | unsigned char buf[CHUNK]; // input buffer | 139 | unsigned char buf[CHUNK]; // input buffer |