Check for error returns from inflateInit() At present, it is sufficient to ensure that an error return from inflateInit() is not ignored. Most error returns, like Z_VERSION_ERROR and Z_STREAM_ERROR, indicate programming or build errors. These errors could, perhaps, be handled with simple asserts. However, for a Z_MEM_ERROR, we may want to perform some further error handling in the future. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
diff --git a/src/odb.c b/src/odb.c
index 562c86c..a77eac7 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -310,9 +310,14 @@ static void set_stream_output(z_stream *s, void *out, size_t len)
static int start_inflate(z_stream *s, gitfo_buf *obj, void *out, size_t len)
{
+ int status;
+
init_stream(s, out, len);
set_stream_input(s, obj->data, obj->len);
- inflateInit(s);
+
+ if ((status = inflateInit(s)) < Z_OK)
+ return status;
+
return inflate(s, 0);
}
@@ -377,7 +382,8 @@ static int inflate_buffer(void *in, size_t inlen, void *out, size_t outlen)
init_stream(&zs, out, outlen);
set_stream_input(&zs, in, inlen);
- inflateInit(&zs);
+ if (inflateInit(&zs) < Z_OK)
+ return GIT_ERROR;
while (status == Z_OK)
status = inflate(&zs, Z_FINISH);