commit - 2cafc7864a7ffed14fede7310877bc28c6e7ef8f
commit + d71015b33dbfbef534be92e584006caddbf16aa6
blob - e3bcc46c3b9a45e6960c6ddc97f2e530e28329cd
blob + 11a24fdcbb22ef869c3b17bf02354c6f7a580e97
--- 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 - 60434b412cdbc4824102355a4d0931b6f95ec7ec
blob + e8f06f56c03a04d123c91c39f96c6bc046cb71d9
--- 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;
}