Skip to content

Commit

Permalink
libibnetdisc: Correct argument order in calloc call to fix warning
Browse files Browse the repository at this point in the history
This commit fixes a compiler warning related to the use of calloc.
```
libibnetdisc/ibnetdisc_cache.c:560:36: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
  560 |                       calloc(sizeof(*node->ports), node->numports + 1))) {
      |                                    ^
libibnetdisc/ibnetdisc_cache.c:560:36: note: earlier argument should specify number of elements, later size of each element
```

The warning was due to transposed arguments in the calloc call, where the
number of elements and the size of each element were specified in the wrong
order.

The correct order for calloc's arguments is:
void *calloc(size_t nmemb, size_t size)

Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
  • Loading branch information
zhijianli88 committed Nov 13, 2024
1 parent fbcbb4e commit 191a5fe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion libibnetdisc/ibnetdisc_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ static int _rebuild_nodes(ibnd_fabric_cache_t * fabric_cache)
/* Rebuild node ports array */

if (!(node->ports =
calloc(sizeof(*node->ports), node->numports + 1))) {
calloc(node->numports + 1, sizeof(*node->ports)))) {
IBND_DEBUG("OOM: node->ports\n");
return -1;
}
Expand Down

0 comments on commit 191a5fe

Please # to comment.