1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
Description: Fix a couple of issues reported by cppcheck.
Forwarded: no
Author: Peter Pentchev <roam@ringlet.net>
Last-Update: 2025-10-24
--- a/src/lib/comp/nocomp/nocomp.c
+++ b/src/lib/comp/nocomp/nocomp.c
@@ -49,7 +49,7 @@
ALLOCD_INT(zck, comp);
*dst = zmalloc(src_size);
- if (!dst) {
+ if (!*dst) {
zck_log(ZCK_LOG_ERROR, "OOM in %s", __func__);
return 0;
}
--- a/src/lib/comp/zstd/zstd.c
+++ b/src/lib/comp/zstd/zstd.c
@@ -150,7 +150,7 @@
}
*dst = zmalloc(max_size);
- if (!dst) {
+ if (!*dst) {
zck_log(ZCK_LOG_ERROR, "OOM in %s", __func__);
return false;
}
--- a/src/lib/header.c
+++ b/src/lib/header.c
@@ -346,13 +346,13 @@
int phs = 5 + 2*MAX_COMP_SIZE + zck->hash_type.digest_size;
char *header = zmalloc(phs);
size_t length = 0;
- memcpy(header, "\0ZCK1", 5);
- length += 5;
if (!header) {
zck_log(ZCK_LOG_ERROR, "OOM in %s", __func__);
return false;
}
+ memcpy(header, "\0ZCK1", 5);
+ length += 5;
/* Write out full data and header hash type */
compint_from_size(header + length, zck->hash_type.type, &length);
/* Write out header length */
--- a/src/lib/zck.c
+++ b/src/lib/zck.c
@@ -437,7 +437,7 @@
zckCtx *zck = zmalloc(sizeof(zckCtx));
if (!zck) {
zck_log(ZCK_LOG_ERROR, "OOM in %s", __func__);
- return false;
+ return NULL;
}
zck->prep_hash_type = -1;
zck->prep_hdr_size = -1;
--- a/src/zck_gen_zdict.c
+++ b/src/zck_gen_zdict.c
@@ -341,6 +341,7 @@
if(dp->d_name[0] == '.')
continue;
char *full_path = calloc(strlen(dir) + strlen(dp->d_name) + 2, 1);
+ assert(full_path);
snprintf(full_path, strlen(dir) + strlen(dp->d_name) + 2, "%s/%s",
dir, dp->d_name);
if(unlink(full_path) != 0) {
|