1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

Fix -Wcalloc-transposed-args

Fixes warnings like:
```
unittest/libmariadb/bulk1.c: In function ‘bulk1’:
unittest/libmariadb/bulk1.c:77:43: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
   77 |   lengths= (unsigned long *)calloc(sizeof(long), TEST_ARRAY_SIZE);
      |                                           ^~~~
unittest/libmariadb/bulk1.c:77:43: note: earlier argument should specify number of elements, later size of each element
unittest/libmariadb/bulk1.c:78:39: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argu
ment and not in the later argument [-Werror=calloc-transposed-args]
   78 |   vals= (unsigned int *)calloc(sizeof(int), TEST_ARRAY_SIZE);
      |                                       ^~~
```

The calloc prototype is:
```
void *calloc(size_t nmemb, size_t size);
```

So, just swap the number of members and size arguments to match the
prototype, as we're initialising N struct of size Y. GCC then sees we're not
doing anything wrong.

Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Sam James
2024-03-04 04:33:30 +00:00
committed by Georg Richter
parent 4c1c7f37d6
commit 51b2a621b3
2 changed files with 3 additions and 3 deletions

View File

@@ -132,7 +132,7 @@ static TRACE_INFO *get_trace_info(unsigned long thread_id)
info= (TRACE_INFO *)info->next;
}
if (!(info= (TRACE_INFO *)calloc(sizeof(TRACE_INFO), 1)))
if (!(info= (TRACE_INFO *)calloc(1, sizeof(TRACE_INFO))))
return NULL;
info->thread_id= thread_id;
info->next= trace_info;