aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2024-02-02 13:39:10 -0800
committerMark Adler <madler@alumni.caltech.edu>2024-02-04 18:48:30 -0800
commitbe4db0a79add326bf06ff46b550f564288749f90 (patch)
treee0b89cf21a370b9a08f6abcbed6899ed4b880b7a /examples
parentf1f503da85d52e56aae11557b4d79a42bcaa2b86 (diff)
downloadzlib-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')
-rw-r--r--examples/zran.c4
-rw-r--r--examples/zran.h2
2 files changed, 5 insertions, 1 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.
132int deflate_index_build(FILE *in, off_t span, struct deflate_index **built) { 132int 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
diff --git a/examples/zran.h b/examples/zran.h
index ebf780d..8a332d6 100644
--- a/examples/zran.h
+++ b/examples/zran.h
@@ -30,7 +30,7 @@ struct deflate_index {
30// the number of access points on success (>= 1), Z_MEM_ERROR for out of 30// the number of access points on success (>= 1), Z_MEM_ERROR for out of
31// memory, Z_BUF_ERROR for a premature end of input, Z_DATA_ERROR for a format 31// memory, Z_BUF_ERROR for a premature end of input, Z_DATA_ERROR for a format
32// or verification error in the input file, or Z_ERRNO for a file read error. 32// or verification error in the input file, or Z_ERRNO for a file read error.
33// On success, *built points to the resulting index. 33// On success, *built points to the resulting index, otherwise it's NULL.
34int deflate_index_build(FILE *in, off_t span, struct deflate_index **built); 34int deflate_index_build(FILE *in, off_t span, struct deflate_index **built);
35 35
36// Use the index to read len bytes from offset into buf. Return the number of 36// Use the index to read len bytes from offset into buf. Return the number of