Skip to content

Commit

Permalink
cppcheck: (warning) Possible null pointer dereference: nvh
Browse files Browse the repository at this point in the history
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 <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #9732
  • Loading branch information
behlendorf committed Dec 19, 2019
1 parent 487bdda commit d16a207
Showing 1 changed file with 3 additions and 1 deletion.
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

0 comments on commit d16a207

Please sign in to comment.