Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cppcheck 1.82 warnings #9732

Closed
wants to merge 8 commits into from
90 changes: 44 additions & 46 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5102,7 +5102,6 @@ parse_fs_perm(fs_perm_t *fsperm, nvlist_t *nvl)
zfs_deleg_who_type_t perm_type = name[0];
char perm_locality = name[1];
const char *perm_name = name + 3;
boolean_t is_set = B_TRUE;
who_perm_t *who_perm = NULL;

assert('$' == name[2]);
Expand Down Expand Up @@ -5132,57 +5131,56 @@ parse_fs_perm(fs_perm_t *fsperm, nvlist_t *nvl)
assert(!"unhandled zfs_deleg_who_type_t");
}

if (is_set) {
who_perm_node_t *found_node = NULL;
who_perm_node_t *node = safe_malloc(
sizeof (who_perm_node_t));
who_perm = &node->who_perm;
uu_avl_index_t idx = 0;

uu_avl_node_init(node, &node->who_avl_node, avl_pool);
who_perm_init(who_perm, fsperm, perm_type, perm_name);

if ((found_node = uu_avl_find(avl, node, NULL, &idx))
== NULL) {
if (avl == fsperm->fsp_uge_avl) {
uid_t rid = 0;
struct passwd *p = NULL;
struct group *g = NULL;
const char *nice_name = NULL;

switch (perm_type) {
case ZFS_DELEG_USER_SETS:
case ZFS_DELEG_USER:
rid = atoi(perm_name);
p = getpwuid(rid);
if (p)
nice_name = p->pw_name;
break;
case ZFS_DELEG_GROUP_SETS:
case ZFS_DELEG_GROUP:
rid = atoi(perm_name);
g = getgrgid(rid);
if (g)
nice_name = g->gr_name;
break;
who_perm_node_t *found_node = NULL;
who_perm_node_t *node = safe_malloc(
sizeof (who_perm_node_t));
who_perm = &node->who_perm;
uu_avl_index_t idx = 0;

default:
break;
}
uu_avl_node_init(node, &node->who_avl_node, avl_pool);
who_perm_init(who_perm, fsperm, perm_type, perm_name);

if ((found_node = uu_avl_find(avl, node, NULL, &idx))
== NULL) {
if (avl == fsperm->fsp_uge_avl) {
uid_t rid = 0;
struct passwd *p = NULL;
struct group *g = NULL;
const char *nice_name = NULL;

switch (perm_type) {
case ZFS_DELEG_USER_SETS:
case ZFS_DELEG_USER:
rid = atoi(perm_name);
p = getpwuid(rid);
if (p)
nice_name = p->pw_name;
break;
case ZFS_DELEG_GROUP_SETS:
case ZFS_DELEG_GROUP:
rid = atoi(perm_name);
g = getgrgid(rid);
if (g)
nice_name = g->gr_name;
break;

if (nice_name != NULL)
(void) strlcpy(
node->who_perm.who_ug_name,
nice_name, 256);
default:
break;
}

uu_avl_insert(avl, node, idx);
} else {
node = found_node;
who_perm = &node->who_perm;
if (nice_name != NULL)
(void) strlcpy(
node->who_perm.who_ug_name,
nice_name, 256);
}

uu_avl_insert(avl, node, idx);
} else {
node = found_node;
who_perm = &node->who_perm;
}
VERIFY3P(who_perm, !=, NULL);

assert(who_perm != NULL);
(void) parse_who_perm(who_perm, nvl2, perm_locality);
}

Expand Down
33 changes: 19 additions & 14 deletions lib/libefi/rdwr_efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,11 @@ efi_alloc_and_init(int fd, uint32_t nparts, struct dk_gpt **vtoc)
length = sizeof (struct dk_gpt) +
sizeof (struct dk_part) * (nparts - 1);

if ((*vtoc = calloc(1, length)) == NULL)
vptr = calloc(1, length);
if (vptr == NULL)
return (-1);

vptr = *vtoc;
*vtoc = vptr;

vptr->efi_version = EFI_VERSION_CURRENT;
vptr->efi_lbasize = lbsize;
Expand Down Expand Up @@ -431,30 +432,32 @@ efi_alloc_and_read(int fd, struct dk_gpt **vtoc)
int rval;
uint32_t nparts;
int length;
struct dk_gpt *vptr;

/* figure out the number of entries that would fit into 16K */
nparts = EFI_MIN_ARRAY_SIZE / sizeof (efi_gpe_t);
length = (int) sizeof (struct dk_gpt) +
(int) sizeof (struct dk_part) * (nparts - 1);
if ((*vtoc = calloc(1, length)) == NULL)
vptr = calloc(1, length);

if (vptr == NULL)
return (VT_ERROR);

(*vtoc)->efi_nparts = nparts;
rval = efi_read(fd, *vtoc);
vptr->efi_nparts = nparts;
rval = efi_read(fd, vptr);

if ((rval == VT_EINVAL) && (*vtoc)->efi_nparts > nparts) {
if ((rval == VT_EINVAL) && vptr->efi_nparts > nparts) {
void *tmp;
length = (int) sizeof (struct dk_gpt) +
(int) sizeof (struct dk_part) *
((*vtoc)->efi_nparts - 1);
nparts = (*vtoc)->efi_nparts;
if ((tmp = realloc(*vtoc, length)) == NULL) {
free (*vtoc);
(int) sizeof (struct dk_part) * (vptr->efi_nparts - 1);
nparts = vptr->efi_nparts;
if ((tmp = realloc(vptr, length)) == NULL) {
free(vptr);
*vtoc = NULL;
return (VT_ERROR);
} else {
*vtoc = tmp;
rval = efi_read(fd, *vtoc);
vptr = tmp;
rval = efi_read(fd, vptr);
}
}

Expand All @@ -463,8 +466,10 @@ efi_alloc_and_read(int fd, struct dk_gpt **vtoc)
(void) fprintf(stderr,
"read of EFI table failed, rval=%d\n", rval);
}
free (*vtoc);
free(vptr);
*vtoc = NULL;
} else {
*vtoc = vptr;
}

return (rval);
Expand Down
7 changes: 2 additions & 5 deletions module/icp/algs/modes/ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,15 +885,13 @@ ccm_init_ctx(ccm_ctx_t *ccm_ctx, char *param, int kmflag,

ccm_ctx->ccm_flags |= CCM_MODE;
} else {
rv = CRYPTO_MECHANISM_PARAM_INVALID;
goto out;
return (CRYPTO_MECHANISM_PARAM_INVALID);
}

if (ccm_init(ccm_ctx, ccm_param->nonce, ccm_param->ulNonceSize,
ccm_param->authData, ccm_param->ulAuthDataSize, block_size,
encrypt_block, xor_block) != 0) {
rv = CRYPTO_MECHANISM_PARAM_INVALID;
goto out;
return (CRYPTO_MECHANISM_PARAM_INVALID);
}
if (!is_encrypt_init) {
/* allocate buffer for storing decrypted plaintext */
Expand All @@ -903,7 +901,6 @@ ccm_init_ctx(ccm_ctx_t *ccm_ctx, char *param, int kmflag,
rv = CRYPTO_HOST_MEMORY;
}
}
out:
return (rv);
}

Expand Down
10 changes: 4 additions & 6 deletions module/icp/algs/modes/gcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,16 +557,15 @@ gcm_init_ctx(gcm_ctx_t *gcm_ctx, char *param, size_t block_size,
rv = CRYPTO_SUCCESS;
gcm_ctx->gcm_flags |= GCM_MODE;
} else {
rv = CRYPTO_MECHANISM_PARAM_INVALID;
goto out;
return (CRYPTO_MECHANISM_PARAM_INVALID);
}

if (gcm_init(gcm_ctx, gcm_param->pIv, gcm_param->ulIvLen,
gcm_param->pAAD, gcm_param->ulAADLen, block_size,
encrypt_block, copy_block, xor_block) != 0) {
rv = CRYPTO_MECHANISM_PARAM_INVALID;
}
out:

return (rv);
}

Expand All @@ -592,16 +591,15 @@ gmac_init_ctx(gcm_ctx_t *gcm_ctx, char *param, size_t block_size,
rv = CRYPTO_SUCCESS;
gcm_ctx->gcm_flags |= GMAC_MODE;
} else {
rv = CRYPTO_MECHANISM_PARAM_INVALID;
goto out;
return (CRYPTO_MECHANISM_PARAM_INVALID);
}

if (gcm_init(gcm_ctx, gmac_param->pIv, AES_GMAC_IV_LEN,
gmac_param->pAAD, gmac_param->ulAADLen, block_size,
encrypt_block, copy_block, xor_block) != 0) {
rv = CRYPTO_MECHANISM_PARAM_INVALID;
}
out:

return (rv);
}

Expand Down
1 change: 1 addition & 0 deletions module/lua/ldebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ static void kname (Proto *p, int pc, int c, const char **name) {
if (ISK(c)) { /* is 'c' a constant? */
TValue *kvalue = &p->k[INDEXK(c)];
if (ttisstring(kvalue)) { /* literal constant? */
// cppcheck-suppress autoVariables
*name = svalue(kvalue); /* it is its own name */
return;
}
Expand Down
1 change: 1 addition & 0 deletions module/lua/ldo.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
struct lua_longjmp lj;
lj.status = LUA_OK;
lj.previous = L->errorJmp; /* chain new error handler */
// cppcheck-suppress autoVariables
L->errorJmp = &lj;
LUAI_TRY(L, &lj,
(*f)(L, ud);
Expand Down
4 changes: 3 additions & 1 deletion module/nvpair/nvpair.c
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,7 @@ nvlist_common(nvlist_t *nvl, char *buf, size_t *buflen, int encoding,
#else
int host_endian = 0;
#endif /* _LITTLE_ENDIAN */
nvs_header_t *nvh = (void *)buf;
nvs_header_t *nvh;

if (buflen == NULL || nvl == NULL ||
(nvs.nvs_priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv) == NULL)
Expand All @@ -2578,6 +2578,7 @@ nvlist_common(nvlist_t *nvl, char *buf, size_t *buflen, int encoding,
if (buf == NULL || *buflen < sizeof (nvs_header_t))
return (EINVAL);

nvh = (void *)buf;
nvh->nvh_encoding = encoding;
nvh->nvh_endian = nvl_endian = host_endian;
nvh->nvh_reserved1 = 0;
Expand All @@ -2589,6 +2590,7 @@ nvlist_common(nvlist_t *nvl, char *buf, size_t *buflen, int encoding,
return (EINVAL);

/* get method of encoding from first byte */
nvh = (void *)buf;
encoding = nvh->nvh_encoding;
nvl_endian = nvh->nvh_endian;
break;
Expand Down
4 changes: 3 additions & 1 deletion module/os/linux/spl/spl-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ int64_t
__divdi3(int64_t u, int64_t v)
{
int64_t q, t;
// cppcheck-suppress shiftTooManyBitsSigned
q = __udivdi3(abs64(u), abs64(v));
// cppcheck-suppress shiftTooManyBitsSigned
t = (u ^ v) >> 63; // If u, v have different
return ((q ^ t) - t); // signs, negate q.
}
Expand Down Expand Up @@ -697,7 +699,7 @@ static void __init
spl_random_init(void)
{
uint64_t s[2];
int i;
int i = 0;

get_random_bytes(s, sizeof (s));

Expand Down
13 changes: 7 additions & 6 deletions module/os/linux/spl/spl-kmem-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ static spl_kmem_slab_t *
spl_slab_alloc(spl_kmem_cache_t *skc, int flags)
{
spl_kmem_slab_t *sks;
spl_kmem_obj_t *sko, *n;
spl_kmem_obj_t *sko;
void *base, *obj;
uint32_t obj_size, offslab_size = 0;
int i, rc = 0;
Expand Down Expand Up @@ -388,6 +388,7 @@ spl_slab_alloc(spl_kmem_cache_t *skc, int flags)

out:
if (rc) {
spl_kmem_obj_t *n = NULL;
if (skc->skc_flags & KMC_OFFSLAB)
list_for_each_entry_safe(sko,
n, &sks->sks_free_list, sko_list) {
Expand Down Expand Up @@ -437,8 +438,8 @@ spl_slab_free(spl_kmem_slab_t *sks,
static void
spl_slab_reclaim(spl_kmem_cache_t *skc)
{
spl_kmem_slab_t *sks, *m;
spl_kmem_obj_t *sko, *n;
spl_kmem_slab_t *sks = NULL, *m = NULL;
spl_kmem_obj_t *sko = NULL, *n = NULL;
LIST_HEAD(sks_list);
LIST_HEAD(sko_list);
uint32_t size = 0;
Expand Down Expand Up @@ -834,7 +835,7 @@ spl_magazine_free(spl_kmem_magazine_t *skm)
static int
spl_magazine_create(spl_kmem_cache_t *skc)
{
int i;
int i = 0;

if (skc->skc_flags & KMC_NOMAGAZINE)
return (0);
Expand Down Expand Up @@ -865,7 +866,7 @@ static void
spl_magazine_destroy(spl_kmem_cache_t *skc)
{
spl_kmem_magazine_t *skm;
int i;
int i = 0;

if (skc->skc_flags & KMC_NOMAGAZINE)
return;
Expand Down Expand Up @@ -1644,7 +1645,7 @@ static spl_shrinker_t
__spl_kmem_cache_generic_shrinker(struct shrinker *shrink,
struct shrink_control *sc)
{
spl_kmem_cache_t *skc;
spl_kmem_cache_t *skc = NULL;
int alloc = 0;

/*
Expand Down
4 changes: 2 additions & 2 deletions module/os/linux/spl/spl-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ kmem_del_init(spinlock_t *lock, struct hlist_head *table,
int bits, const void *addr)
{
struct hlist_head *head;
struct hlist_node *node;
struct hlist_node *node = NULL;
struct kmem_debug *p;
unsigned long flags;

Expand Down Expand Up @@ -573,7 +573,7 @@ static void
spl_kmem_fini_tracking(struct list_head *list, spinlock_t *lock)
{
unsigned long flags;
kmem_debug_t *kd;
kmem_debug_t *kd = NULL;
char str[17];

spin_lock_irqsave(lock, flags);
Expand Down
Loading