gcc 11 cleanup

Compiling with gcc 11.1.0 produces three new warnings.
Change the code slightly to avoid them.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Attila Fülöp <attila@fueloep.org>
Closes #12130
Closes #12188
Closes #12237
This commit is contained in:
Attila Fülöp
2021-06-24 01:57:06 +02:00
committed by Tony Hutter
parent 820c95750b
commit fb9eee4cc2
4 changed files with 27 additions and 13 deletions
+10 -2
View File
@@ -82,7 +82,11 @@ alloc_pw_size(size_t len)
return (NULL);
}
pw->len = len;
pw->value = malloc(len);
/*
* The use of malloc() triggers a spurious gcc 11 -Wmaybe-uninitialized
* warning in the mlock() function call below, so use calloc().
*/
pw->value = calloc(len, 1);
if (!pw->value) {
free(pw);
return (NULL);
@@ -99,7 +103,11 @@ alloc_pw_string(const char *source)
return (NULL);
}
pw->len = strlen(source) + 1;
pw->value = malloc(pw->len);
/*
* The use of malloc() triggers a spurious gcc 11 -Wmaybe-uninitialized
* warning in the mlock() function call below, so use calloc().
*/
pw->value = calloc(pw->len, 1);
if (!pw->value) {
free(pw);
return (NULL);