misc: fix -Walloc-size warnings

GCC 14 introduces a new -Walloc-size included in -Wextra which gives:

```
src/tool_operate.c: In function ‘add_per_transfer’:
src/tool_operate.c:213:5: warning: allocation of insufficient size ‘1’ for type ‘struct per_transfer’ with size ‘480’ [-Walloc-size]
  213 |   p = calloc(sizeof(struct per_transfer), 1);
      |     ^
src/var.c: In function ‘addvariable’:
src/var.c:361:5: warning: allocation of insufficient size ‘1’ for type ‘struct var’ with size ‘32’ [-Walloc-size]
  361 |   p = calloc(sizeof(struct var), 1);
      |     ^
```

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 1 struct of size `sizeof(struct
...)`. GCC then sees we're not doing anything wrong.

Closes #12292
This commit is contained in:
Sam James 2023-11-07 23:22:58 +00:00 committed by Daniel Stenberg
parent d06643812c
commit bc8509a748
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
30 changed files with 40 additions and 40 deletions

View file

@ -211,7 +211,7 @@ static curl_off_t all_pers;
static CURLcode add_per_transfer(struct per_transfer **per)
{
struct per_transfer *p;
p = calloc(sizeof(struct per_transfer), 1);
p = calloc(1, sizeof(struct per_transfer));
if(!p)
return CURLE_OUT_OF_MEMORY;
if(!transfers)

View file

@ -358,7 +358,7 @@ static ParameterError addvariable(struct GlobalConfig *global,
if(check)
notef(global, "Overwriting variable '%s'", check->name);
p = calloc(sizeof(struct var), 1);
p = calloc(1, sizeof(struct var));
if(!p)
return PARAM_NO_MEM;