Silence two instances of -Wcalloc-transposed-args

Message ID 20240428234618.25964-1-peter0x44@disroot.org
State New
Headers
Series Silence two instances of -Wcalloc-transposed-args |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Testing passed

Commit Message

Peter Damianov April 28, 2024, 11:46 p.m. UTC
  Signed-off-by: Peter Damianov <peter0x44@disroot.org>
---

Fixes these warnings:

../../gcc/gcc/../libgcc/libgcov-util.c: In function 'void tag_counters(unsigned int, int)':
../../gcc/gcc/../libgcc/libgcov-util.c:214:59: warning: 'void* calloc(size_t, size_t)' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
  214 |   k_ctrs[tag_ix].values = values = (gcov_type *) xcalloc (sizeof (gcov_type),
      |                                                           ^~~~~~~~~~~~~~~~~~
../../gcc/gcc/../libgcc/libgcov-util.c:214:59: note: earlier argument should specify number of elements, later size of each element

../../gcc/gcc/../libgcc/libgcov-util.c: In function 'void topn_to_memory_representation(gcov_ctr_info*)':
../../gcc/gcc/../libgcc/libgcov-util.c:529:43: warning: 'void* calloc(size_t, size_t)' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
  529 |             = (struct gcov_kvp *)xcalloc (sizeof (struct gcov_kvp), n);
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~
../../gcc/gcc/../libgcc/libgcov-util.c:529:43: note: earlier argument should specify number of elements, later size of each element

I think this can be applied as obvious.

 libgcc/libgcov-util.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Richard Biener May 2, 2024, 10:50 a.m. UTC | #1
On Mon, Apr 29, 2024 at 1:48 AM Peter Damianov <peter0x44@disroot.org> wrote:
>
> Signed-off-by: Peter Damianov <peter0x44@disroot.org>
> ---
>
> Fixes these warnings:
>
> ../../gcc/gcc/../libgcc/libgcov-util.c: In function 'void tag_counters(unsigned int, int)':
> ../../gcc/gcc/../libgcc/libgcov-util.c:214:59: warning: 'void* calloc(size_t, size_t)' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
>   214 |   k_ctrs[tag_ix].values = values = (gcov_type *) xcalloc (sizeof (gcov_type),
>       |                                                           ^~~~~~~~~~~~~~~~~~
> ../../gcc/gcc/../libgcc/libgcov-util.c:214:59: note: earlier argument should specify number of elements, later size of each element
>
> ../../gcc/gcc/../libgcc/libgcov-util.c: In function 'void topn_to_memory_representation(gcov_ctr_info*)':
> ../../gcc/gcc/../libgcc/libgcov-util.c:529:43: warning: 'void* calloc(size_t, size_t)' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
>   529 |             = (struct gcov_kvp *)xcalloc (sizeof (struct gcov_kvp), n);
>       |                                           ^~~~~~~~~~~~~~~~~~~~~~~~
> ../../gcc/gcc/../libgcc/libgcov-util.c:529:43: note: earlier argument should specify number of elements, later size of each element
>
> I think this can be applied as obvious.

Agreed.  Note that patches need a specially formatted ChangeLog as
part of the commit message,
like for example

libgcc/
            * libgcov-util.c (tag_counters): Swap xcalloc arguments.
            (topn_to_memory_representation): Likewise.

with tabs to indent.

Richard.

>  libgcc/libgcov-util.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c
> index ba4b90a480d..f443408c4ab 100644
> --- a/libgcc/libgcov-util.c
> +++ b/libgcc/libgcov-util.c
> @@ -211,8 +211,8 @@ tag_counters (unsigned tag, int length)
>    gcc_assert (k_ctrs[tag_ix].num == 0);
>    k_ctrs[tag_ix].num = n_counts;
>
> -  k_ctrs[tag_ix].values = values = (gcov_type *) xcalloc (sizeof (gcov_type),
> -                                                         n_counts);
> +  k_ctrs[tag_ix].values = values = (gcov_type *) xcalloc (n_counts,
> +                                                         sizeof (gcov_type));
>    gcc_assert (values);
>
>    if (length > 0)
> @@ -526,7 +526,7 @@ topn_to_memory_representation (struct gcov_ctr_info *info)
>        if (n > 0)
>         {
>           struct gcov_kvp *tuples
> -           = (struct gcov_kvp *)xcalloc (sizeof (struct gcov_kvp), n);
> +           = (struct gcov_kvp *)xcalloc (n, sizeof (struct gcov_kvp));
>           for (unsigned i = 0; i < n - 1; i++)
>             tuples[i].next = &tuples[i + 1];
>           for (unsigned i = 0; i < n; i++)
> --
> 2.39.2
>
  

Patch

diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c
index ba4b90a480d..f443408c4ab 100644
--- a/libgcc/libgcov-util.c
+++ b/libgcc/libgcov-util.c
@@ -211,8 +211,8 @@  tag_counters (unsigned tag, int length)
   gcc_assert (k_ctrs[tag_ix].num == 0);
   k_ctrs[tag_ix].num = n_counts;
 
-  k_ctrs[tag_ix].values = values = (gcov_type *) xcalloc (sizeof (gcov_type),
-							  n_counts);
+  k_ctrs[tag_ix].values = values = (gcov_type *) xcalloc (n_counts,
+							  sizeof (gcov_type));
   gcc_assert (values);
 
   if (length > 0)
@@ -526,7 +526,7 @@  topn_to_memory_representation (struct gcov_ctr_info *info)
       if (n > 0)
 	{
 	  struct gcov_kvp *tuples
-	    = (struct gcov_kvp *)xcalloc (sizeof (struct gcov_kvp), n);
+	    = (struct gcov_kvp *)xcalloc (n, sizeof (struct gcov_kvp));
 	  for (unsigned i = 0; i < n - 1; i++)
 	    tuples[i].next = &tuples[i + 1];
 	  for (unsigned i = 0; i < n; i++)