commit - 7c0429dc438232f6419f9b5d4573d80dbfe5331d
commit + 87e39f6fda462e8970d01e25e079c5f57b3248c5
blob - 89562361089d480759e5366d089156845be28b49
blob + fe2728a676b7c095d0226a5dfa34fa65b7149d33
--- lib/deflate.c
+++ lib/deflate.c
#define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
#endif
+static const struct got_error *
+wrap_deflate_error(int zerr, const char *prefix)
+{
+ if (zerr == Z_ERRNO)
+ return got_error_from_errno(prefix);
+ if (zerr == Z_MEM_ERROR)
+ return got_error_set_errno(ENOMEM, prefix);
+
+ return got_error(GOT_ERR_COMPRESSION);
+}
+
const struct got_error *
got_deflate_init(struct got_deflate_buf *zb, uint8_t *outbuf, size_t bufsize)
{
zb->z.zalloc = Z_NULL;
zb->z.zfree = Z_NULL;
zerr = deflateInit(&zb->z, Z_DEFAULT_COMPRESSION);
- if (zerr != Z_OK) {
- if (zerr == Z_ERRNO)
- return got_error_from_errno("deflateInit");
- if (zerr == Z_MEM_ERROR) {
- errno = ENOMEM;
- return got_error_from_errno("deflateInit");
- }
- return got_error(GOT_ERR_COMPRESSION);
- }
+ if (zerr != Z_OK)
+ return wrap_deflate_error(zerr, "deflateInit");
zb->inlen = zb->outlen = bufsize;
zb->flags |= GOT_DEFLATE_F_HAVE_MORE;
} else {
if (ret != Z_STREAM_END)
- return got_error(GOT_ERR_COMPRESSION);
+ return wrap_deflate_error(ret, "deflate");
zb->flags &= ~GOT_DEFLATE_F_HAVE_MORE;
}
zb->flags |= GOT_DEFLATE_F_HAVE_MORE;
} else {
if (ret != Z_STREAM_END)
- return got_error(GOT_ERR_COMPRESSION);
+ return wrap_deflate_error(ret, "deflate");
zb->flags &= ~GOT_DEFLATE_F_HAVE_MORE;
}
ret = deflate(z, Z_FINISH);
if (ret != Z_STREAM_END && ret != Z_OK)
- return got_error(GOT_ERR_COMPRESSION);
+ return wrap_deflate_error(ret, "deflate");
avail = z->total_out - last_total_out;
if (avail > 0) {
blob - a59c766edfa1a6912c2c7c02cc0d66b896bba049
blob + 98bcc564cfc958b30147df6f23636bb01f6dc6dd
--- lib/inflate.c
+++ lib/inflate.c
#define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
#endif
+static const struct got_error *
+wrap_inflate_error(int zerr, const char *prefix)
+{
+ if (zerr == Z_ERRNO)
+ return got_error_from_errno(prefix);
+ if (zerr == Z_MEM_ERROR)
+ return got_error_set_errno(ENOMEM, prefix);
+
+ return got_error(GOT_ERR_DECOMPRESSION);
+}
+
const struct got_error *
got_inflate_init(struct got_inflate_buf *zb, uint8_t *outbuf, size_t bufsize,
struct got_inflate_checksum *csum)
zb->z.zalloc = Z_NULL;
zb->z.zfree = Z_NULL;
zerr = inflateInit(&zb->z);
- if (zerr != Z_OK) {
- if (zerr == Z_ERRNO)
- return got_error_from_errno("inflateInit");
- if (zerr == Z_MEM_ERROR) {
- errno = ENOMEM;
- return got_error_from_errno("inflateInit");
- }
- return got_error(GOT_ERR_DECOMPRESSION);
- }
+ if (zerr != Z_OK)
+ return wrap_inflate_error(zerr, "inflateInit");
zb->inlen = zb->outlen = bufsize;
zb->flags |= GOT_INFLATE_F_HAVE_MORE;
} else {
if (ret != Z_STREAM_END)
- return got_error(GOT_ERR_DECOMPRESSION);
+ return wrap_inflate_error(ret, "inflate");
zb->flags &= ~GOT_INFLATE_F_HAVE_MORE;
}
zb->flags |= GOT_INFLATE_F_HAVE_MORE;
} else {
if (ret != Z_STREAM_END)
- return got_error(GOT_ERR_DECOMPRESSION);
+ return wrap_inflate_error(ret, "inflate");
zb->flags &= ~GOT_INFLATE_F_HAVE_MORE;
}
zb->flags |= GOT_INFLATE_F_HAVE_MORE;
} else {
if (ret != Z_STREAM_END)
- return got_error(GOT_ERR_DECOMPRESSION);
+ return wrap_inflate_error(ret, "inflate");
zb->flags &= ~GOT_INFLATE_F_HAVE_MORE;
}