From 51b2a621b3d5ef949098dcb7912048caaf878793 Mon Sep 17 00:00:00 2001 From: Sam James Date: Mon, 4 Mar 2024 04:33:30 +0000 Subject: [PATCH] Fix -Wcalloc-transposed-args MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- plugins/io/remote_io.c | 4 ++-- plugins/trace/trace_example.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/io/remote_io.c b/plugins/io/remote_io.c index c06ecacd..eb5b5f37 100644 --- a/plugins/io/remote_io.c +++ b/plugins/io/remote_io.c @@ -279,11 +279,11 @@ MA_FILE *ma_rio_open(const char *url,const char *operation) MA_REMOTE_FILE *rf; (void)operation; - if (!(file = (MA_FILE *)calloc(sizeof(MA_FILE), 1))) + if (!(file = (MA_FILE *)calloc(1, sizeof(MA_FILE)))) return NULL; file->type= MA_FILE_REMOTE; - if (!(file->ptr= rf= (MA_REMOTE_FILE *)calloc(sizeof(MA_REMOTE_FILE), 1))) + if (!(file->ptr= rf= (MA_REMOTE_FILE *)calloc(1, sizeof(MA_REMOTE_FILE)))) { free(file); return NULL; diff --git a/plugins/trace/trace_example.c b/plugins/trace/trace_example.c index 1060542c..e177c206 100644 --- a/plugins/trace/trace_example.c +++ b/plugins/trace/trace_example.c @@ -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;