summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2019-12-16 16:03:31 -0800
committerBrian Behlendorf <[email protected]>2019-12-18 17:25:57 -0800
commitd16a207f2edd19ece593967e7e83b7e2217d04f9 (patch)
tree7269e6e424c9b059ae943de57230d491a96bad57 /module
parent487bddad67f5abf4f4d8020befd5792743ff8657 (diff)
cppcheck: (warning) Possible null pointer dereference: nvh
Move the 'nvh = (void *)buf' assignment after the 'buf == NULL' check to resolve the warning. Interestingly, cppcheck 1.88 correctly determines that the existing code is safe, while cppcheck 1.86 reports the warning. Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #9732
Diffstat (limited to 'module')
-rw-r--r--module/nvpair/nvpair.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/module/nvpair/nvpair.c b/module/nvpair/nvpair.c
index 6c6a58e85..8691aaf2c 100644
--- a/module/nvpair/nvpair.c
+++ b/module/nvpair/nvpair.c
@@ -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)
@@ -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;
@@ -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;