diff options
author | Richard Yao <[email protected]> | 2023-03-11 13:39:24 -0500 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2023-03-14 15:25:50 -0700 |
commit | d1807f168edd09ca26a5a0c6b570686b982808ad (patch) | |
tree | db5bfd360991fa3528fe688247eb289ef1d8b859 /module/nvpair | |
parent | 50f6934b9c1f4aa583592e8a969b934440a44c64 (diff) |
nvpair: Constify string functions
After addressing coverity complaints involving `nvpair_name()`, the
compiler started complaining about dropping const. This lead to a rabbit
hole where not only `nvpair_name()` needed to be constified, but also
`nvpair_value_string()`, `fnvpair_value_string()` and a few other static
functions, plus variable pointers throughout the code. The result became
a fairly big change, so it has been split out into its own patch.
Reviewed-by: Tino Reichardt <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Richard Yao <[email protected]>
Closes #14612
Diffstat (limited to 'module/nvpair')
-rw-r--r-- | module/nvpair/fnvpair.c | 12 | ||||
-rw-r--r-- | module/nvpair/nvpair.c | 16 |
2 files changed, 14 insertions, 14 deletions
diff --git a/module/nvpair/fnvpair.c b/module/nvpair/fnvpair.c index 86b0b4cdf..cc2233c40 100644 --- a/module/nvpair/fnvpair.c +++ b/module/nvpair/fnvpair.c @@ -402,10 +402,10 @@ fnvlist_lookup_uint64(const nvlist_t *nvl, const char *name) return (rv); } -char * -fnvlist_lookup_string(nvlist_t *nvl, const char *name) +const char * +fnvlist_lookup_string(const nvlist_t *nvl, const char *name) { - char *rv; + const char *rv; VERIFY0(nvlist_lookup_string(nvl, name, &rv)); return (rv); } @@ -577,10 +577,10 @@ fnvpair_value_uint64(const nvpair_t *nvp) return (rv); } -char * -fnvpair_value_string(nvpair_t *nvp) +const char * +fnvpair_value_string(const nvpair_t *nvp) { - char *rv; + const char *rv; VERIFY0(nvpair_value_string(nvp, &rv)); return (rv); } diff --git a/module/nvpair/nvpair.c b/module/nvpair/nvpair.c index 023d49601..d9449e47e 100644 --- a/module/nvpair/nvpair.c +++ b/module/nvpair/nvpair.c @@ -473,7 +473,7 @@ nvt_remove_nvpair(nvlist_t *nvl, const nvpair_t *nvp) } i_nvp_t **tab = priv->nvp_hashtable; - char *name = NVP_NAME(nvp); + const char *name = NVP_NAME(nvp); uint64_t hash = nvt_hash(name); uint64_t index = hash & (priv->nvp_nbuckets - 1); @@ -528,7 +528,7 @@ nvt_add_nvpair(nvlist_t *nvl, nvpair_t *nvp) } i_nvp_t **tab = priv->nvp_hashtable; - char *name = NVP_NAME(nvp); + const char *name = NVP_NAME(nvp); uint64_t hash = nvt_hash(name); uint64_t index = hash & (priv->nvp_nbuckets - 1); @@ -1517,7 +1517,7 @@ nvlist_empty(const nvlist_t *nvl) return (priv->nvp_list == NULL); } -char * +const char * nvpair_name(const nvpair_t *nvp) { return (NVP_NAME(nvp)); @@ -1731,7 +1731,7 @@ nvlist_lookup_double(const nvlist_t *nvl, const char *name, double *val) #endif int -nvlist_lookup_string(nvlist_t *nvl, const char *name, char **val) +nvlist_lookup_string(const nvlist_t *nvl, const char *name, const char **val) { return (nvlist_lookup_common(nvl, name, DATA_TYPE_STRING, NULL, val)); } @@ -1917,7 +1917,7 @@ nvlist_lookup_pairs(nvlist_t *nvl, int flag, ...) */ static int nvlist_lookup_nvpair_ei_sep(nvlist_t *nvl, const char *name, const char sep, - nvpair_t **ret, int *ip, char **ep) + nvpair_t **ret, int *ip, const char **ep) { nvpair_t *nvp; const char *np; @@ -2097,7 +2097,7 @@ nvlist_lookup_nvpair(nvlist_t *nvl, const char *name, nvpair_t **ret) * description. */ int nvlist_lookup_nvpair_embedded_index(nvlist_t *nvl, - const char *name, nvpair_t **ret, int *ip, char **ep) + const char *name, nvpair_t **ret, int *ip, const char **ep) { return (nvlist_lookup_nvpair_ei_sep(nvl, name, '.', ret, ip, ep)); } @@ -2192,7 +2192,7 @@ nvpair_value_double(const nvpair_t *nvp, double *val) #endif int -nvpair_value_string(nvpair_t *nvp, char **val) +nvpair_value_string(const nvpair_t *nvp, const char **val) { return (nvpair_value_common(nvp, DATA_TYPE_STRING, NULL, val)); } @@ -2264,7 +2264,7 @@ nvpair_value_uint64_array(nvpair_t *nvp, uint64_t **val, uint_t *nelem) } int -nvpair_value_string_array(nvpair_t *nvp, char ***val, uint_t *nelem) +nvpair_value_string_array(nvpair_t *nvp, const char ***val, uint_t *nelem) { return (nvpair_value_common(nvp, DATA_TYPE_STRING_ARRAY, nelem, val)); } |