Message ID | 20231204161655.1349063-1-slyich@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 2a46979ea328 |
Delegated to: | Petr Lautrbach |
Headers | show |
Series | libsemanage: fix src/genhomedircon.c build on `gcc-14` (`-Werror=alloc-size`) | expand |
On Mon, Dec 4, 2023 at 11:17 AM Sergei Trofimovich <slyich@gmail.com> wrote: > > `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); > | ^ > > Signed-off-by: Sergei Trofimovich <slyich@gmail.com> Acked-by: James Carter <jwcart2@gmail.com> > --- > libsemanage/src/genhomedircon.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/libsemanage/src/genhomedircon.c b/libsemanage/src/genhomedircon.c > index 8f8774d3..66585987 100644 > --- a/libsemanage/src/genhomedircon.c > +++ b/libsemanage/src/genhomedircon.c > @@ -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 > >
On Mon, Dec 4, 2023 at 2:24 PM James Carter <jwcart2@gmail.com> wrote: > > On Mon, Dec 4, 2023 at 11:17 AM Sergei Trofimovich <slyich@gmail.com> wrote: > > > > `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); > > | ^ > > > > Signed-off-by: Sergei Trofimovich <slyich@gmail.com> > > Acked-by: James Carter <jwcart2@gmail.com> > Merged. Thanks, Jim > > --- > > libsemanage/src/genhomedircon.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/libsemanage/src/genhomedircon.c b/libsemanage/src/genhomedircon.c > > index 8f8774d3..66585987 100644 > > --- a/libsemanage/src/genhomedircon.c > > +++ b/libsemanage/src/genhomedircon.c > > @@ -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 > > > >
diff --git a/libsemanage/src/genhomedircon.c b/libsemanage/src/genhomedircon.c index 8f8774d3..66585987 100644 --- a/libsemanage/src/genhomedircon.c +++ b/libsemanage/src/genhomedircon.c @@ -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);
`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); | ^ Signed-off-by: Sergei Trofimovich <slyich@gmail.com> --- libsemanage/src/genhomedircon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)