dedup

deduplicating backup program
git clone git://git.2f30.org/dedup
Log | Files | Refs | README | LICENSE

commit 873ae0109133cf38b38ad3a0466bfed825462b19
parent e952e5814408ad1c170e1276a2e4ef3a4dcaf3c4
Author: sin <sin@2f30.org>
Date:   Fri,  3 May 2019 15:10:20 +0100

Error reporting for bcompress.c

Diffstat:
Mbcompress.c | 33++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/bcompress.c b/bcompress.c @@ -93,16 +93,20 @@ bccreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) struct bops *bops; int type; - if (strcasecmp(bpar->calgo, "none") == 0) + if (strcasecmp(bpar->calgo, "none") == 0) { type = CDNONETYPE; - else if (strcasecmp(bpar->calgo, "snappy") == 0) + } else if (strcasecmp(bpar->calgo, "snappy") == 0) { type = CDSNAPPYTYPE; - else + } else { + bseterr("invalid compression type: %s", bpar->calgo); return -1; + } bctx->cctx = calloc(1, sizeof(struct cctx)); - if (bctx->cctx == NULL) + if (bctx->cctx == NULL) { + bseterr("out of memory"); return -1; + } cctx = bctx->cctx; cctx->type = type; @@ -121,8 +125,10 @@ bcopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) struct bops *bops; bctx->cctx = calloc(1, sizeof(struct cctx)); - if (bctx->cctx == NULL) + if (bctx->cctx == NULL) { + bseterr("out of memory"); return -1; + } cctx = bctx->cctx; bops = bencryptops(); @@ -138,6 +144,7 @@ bcopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) } else { bops->close(bctx); free(cctx); + bseterr("invalid compression type: %s", bpar->calgo); return -1; } return 0; @@ -159,13 +166,16 @@ bcput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) } else if (cctx->type == CDSNAPPYTYPE) { cn = snappy_max_compressed_length(n); } else { + bseterr("invalid compression type: %d", cctx->type); return -1; } /* Allocate compressed block */ cbuf = malloc(CDSIZE + cn); - if (cbuf == NULL) + if (cbuf == NULL) { + bseterr("out of memory"); return -1; + } /* Compress block */ if (cctx->type == CDNONETYPE) { @@ -173,10 +183,12 @@ bcput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) } else if (cctx->type == CDSNAPPYTYPE) { if (snappy_compress(buf, n, &cbuf[CDSIZE], &cn) != SNAPPY_OK) { free(cbuf); + bseterr("failed to compress"); return -1; } } else { free(cbuf); + bseterr("invalid compression type: %d", cctx->type); return -1; } @@ -212,8 +224,10 @@ bcget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n) /* Allocate compressed block */ cbuf = malloc(size); - if (cbuf == NULL) + if (cbuf == NULL) { + bseterr("out of memory"); return -1; + } /* Read compressed block */ bops = bencryptops(); @@ -230,6 +244,7 @@ bcget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n) un = cd.size; if (*n < un) { free(cbuf); + bseterr("buffer too small"); return -1; } memcpy(buf, &cbuf[CDSIZE], un); @@ -237,21 +252,25 @@ bcget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n) if (snappy_uncompressed_length(&cbuf[CDSIZE], cd.size, &un) != SNAPPY_OK) { free(cbuf); + bseterr("failed to determine uncompressed length"); return -1; } if (*n < un) { free(cbuf); + bseterr("buffer too small"); return -1; } if (snappy_uncompress(&cbuf[CDSIZE], cd.size, buf, &un) != SNAPPY_OK) { free(cbuf); + bseterr("failed to uncompress"); return -1; } } else { free(cbuf); + bseterr("invalid compression type: %d", cd.type); return -1; }