Re: [PATCH 1/4] libsepol: reorder calloc(3) arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 5, 2024 at 1:36 PM Christian Göttsche
<cgzones@xxxxxxxxxxxxxx> wrote:
>
> The canonical order of calloc(3) parameters is the number of elements
> first and the size of each element second.
>
> Reported by GCC 14:
>
>     kernel_to_conf.c:814:47: warning: 'calloc' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
>     kernel_to_conf.c:945:46: warning: 'calloc' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
>     kernel_to_conf.c:2109:35: warning: 'calloc' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
>     kernel_to_common.c:578:29: warning: 'calloc' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
>
> Signed-off-by: Christian Göttsche <cgzones@xxxxxxxxxxxxxx>

For these four patches:
Acked-by: James Carter <jwcart2@xxxxxxxxx>

> ---
>  libsepol/src/kernel_to_common.c | 2 +-
>  libsepol/src/kernel_to_conf.c   | 6 +++---
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/libsepol/src/kernel_to_common.c b/libsepol/src/kernel_to_common.c
> index 4612eef3..2422eed0 100644
> --- a/libsepol/src/kernel_to_common.c
> +++ b/libsepol/src/kernel_to_common.c
> @@ -575,7 +575,7 @@ static int sort_ocontext_data(struct ocontext **ocons, int (*cmp)(const void *,
>                 return 0;
>         }
>
> -       data = calloc(sizeof(*data), num);
> +       data = calloc(num, sizeof(*data));
>         if (!data) {
>                 ERR(NULL, "Out of memory");
>                 return -1;
> diff --git a/libsepol/src/kernel_to_conf.c b/libsepol/src/kernel_to_conf.c
> index 83f46e0f..e6b449b4 100644
> --- a/libsepol/src/kernel_to_conf.c
> +++ b/libsepol/src/kernel_to_conf.c
> @@ -811,7 +811,7 @@ static int write_sensitivity_rules_to_conf(FILE *out, struct policydb *pdb)
>         num = strs_num_items(strs);
>
>         if (num > 0) {
> -               sens_alias_map = calloc(sizeof(*sens_alias_map), pdb->p_levels.nprim);
> +               sens_alias_map = calloc(pdb->p_levels.nprim, sizeof(*sens_alias_map));
>                 if (!sens_alias_map) {
>                         rc = -1;
>                         goto exit;
> @@ -942,7 +942,7 @@ static int write_category_rules_to_conf(FILE *out, struct policydb *pdb)
>         num = strs_num_items(strs);
>
>         if (num > 0) {
> -               cat_alias_map = calloc(sizeof(*cat_alias_map), pdb->p_cats.nprim);
> +               cat_alias_map = calloc(pdb->p_cats.nprim, sizeof(*cat_alias_map));
>                 if (!cat_alias_map) {
>                         rc = -1;
>                         goto exit;
> @@ -2106,7 +2106,7 @@ static int write_cond_nodes_to_conf(FILE *out, struct policydb *pdb)
>                 return 0;
>         }
>
> -       cond_data = calloc(sizeof(struct cond_data), num);
> +       cond_data = calloc(num, sizeof(struct cond_data));
>         if (!cond_data) {
>                 rc = -1;
>                 goto exit;
> --
> 2.43.0
>
>





[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux