libsemanage: fix src/genhomedircon.c build on `gcc-14` (`-Werror=alloc-size`)
PATCH 1/1 libsemanage: fix src/genhomedircon.c build on `gcc-14` (`-Werror=alloc-size`)
gcc-14 added a new -Walloc-size warning that makes sure that size of an individual element matches size of a pointed type:
https://gcc.gnu.org/PR71219
libsemanage triggers it on calloc() calls where member size is used as 1 (instead of member count):
genhomedircon.c: In function 'ignore_setup':
genhomedircon.c:152:21:
error: allocation of insufficient size '1' for type 'ignoredir_t'
{aka 'struct IgnoreDir'} with size '16' [-Werror=alloc-size]
152 | ptr = calloc(sizeof(ignoredir_t),1);
| ^
--- libsemanage/src/genhomedircon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libsemanage/src/genhomedircon.c +1 -1
@@ -149,7 +149,7 @@ static int ignore_setup(char *ignoredirs) { tok =strtok (ignoredirs,";" );while (tok) { - ptr =calloc (sizeof (ignoredir_t),1 ); + ptr =calloc (1 ,sizeof (ignoredir_t));if (!ptr) goto err; ptr->dir =strdup (tok);
Signature · 1 line
2.42.0
Quoted 9 lines · Sergei Trofimovich
gcc-14added a new-Walloc-sizewarning that makes sure that size of an individual element matches size of a pointed type:https://gcc.gnu.org/PR71219
libsemanagetriggers it oncalloc()calls where member size is used as1(instead of member count):
Quoted 8 lines
genhomedircon.c: In function 'ignore_setup':
genhomedircon.c:152:21:
error: allocation of insufficient size '1' for type 'ignoredir_t'
{aka 'struct IgnoreDir'} with size '16' [-Werror=alloc-size]
152 | ptr = calloc(sizeof(ignoredir_t),1);
| ^Signed-off-by Sergei Trofimovich <[email protected]>
Quoted 21 lines
--- libsemanage/src/genhomedircon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libsemanage/src/genhomedircon.c +1
-2@@ -149,7 +149,7 @@ static int ignore_setup(char *ignoredirs) { tok =strtok (ignoredirs,";" );while (tok) { - ptr =calloc (sizeof (ignoredir_t),1 ); + ptr =calloc (1 ,sizeof (ignoredir_t));if (!ptr) goto err; ptr->dir =strdup (tok); --2.42.0
Quoted 18 lines · James Carter
Quoted 16 lines · Sergei Trofimovich
gcc-14added a new-Walloc-sizewarning that makes sure that size of an individual element matches size of a pointed type:https://gcc.gnu.org/PR71219
libsemanagetriggers it oncalloc()calls where member size is used as1(instead of member count):
genhomedircon.c: In function 'ignore_setup':
genhomedircon.c:152:21:
error: allocation of insufficient size '1' for type 'ignoredir_t'
{aka 'struct IgnoreDir'} with size '16' [-Werror=alloc-size]
152 | ptr = calloc(sizeof(ignoredir_t),1);
| ^
Quoted 4 lines
Quoted 1 line
Signed-off-by Sergei Trofimovich <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Thanks,
Jim
Quoted 21 lines
Quoted 21 lines
--- libsemanage/src/genhomedircon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libsemanage/src/genhomedircon.c +1
-2@@ -149,7 +149,7 @@ static int ignore_setup(char *ignoredirs) { tok =strtok (ignoredirs,";" );while (tok) { - ptr =calloc (sizeof (ignoredir_t),1 ); + ptr =calloc (1 ,sizeof (ignoredir_t));if (!ptr) goto err; ptr->dir =strdup (tok); --2.42.0