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 <milky-zfs@mcmilk.de>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14612
This commit is contained in:
Richard Yao
2023-03-11 13:39:24 -05:00
committed by Brian Behlendorf
parent 50f6934b9c
commit d1807f168e
72 changed files with 442 additions and 402 deletions
+7 -8
View File
@@ -116,7 +116,7 @@ lzbe_get_boot_device(const char *pool, char **device)
libzfs_handle_t *hdl;
zpool_handle_t *zphdl;
nvlist_t *nv;
char *val;
const char *val;
int rv = -1;
if (pool == NULL || *pool == '\0' || device == NULL)
@@ -140,14 +140,13 @@ lzbe_get_boot_device(const char *pool, char **device)
* we only do need dataset name.
*/
if (strncmp(val, "zfs:", 4) == 0) {
val += 4;
val = strdup(val);
if (val != NULL) {
size_t len = strlen(val);
char *tmp = strdup(val + 4);
if (tmp != NULL) {
size_t len = strlen(tmp);
if (val[len - 1] == ':')
val[len - 1] = '\0';
*device = val;
if (tmp[len - 1] == ':')
tmp[len - 1] = '\0';
*device = tmp;
} else {
rv = ENOMEM;
}