nutanix / libvfio-user

framework for emulating devices in userspace
BSD 3-Clause "New" or "Revised" License
168 stars 51 forks source link

gcc >= 14 hits calloc-transposed-args #801

Closed mikeBashStuff closed 3 months ago

mikeBashStuff commented 3 months ago
libvfio-user: 5af77514b4fc85215d8ca033527ea4db174d1e4b, master

Point of failure:

21/36] Compiling C object lib/libvfio-user.a.p/libvfio-user.c.o
FAILED: lib/libvfio-user.a.p/libvfio-user.c.o
cc -Ilib/libvfio-user.a.p -Ilib -I../../../libvfio-user/lib -Iinclude -I../../../libvfio-user/include -I/usr/include/json-c -fvisibility=hidden -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu99 -O0 -g -gdwarf-4 -fPIC -D_GNU_SOURCE -Werror -DDEBUG -Wno-missing-field-initializers -Wmissing-declarations -Wwrite-strings -MD -MQ lib/libvfio-user.a.p/libvfio-user.c.o -MF lib/libvfio-user.a.p/libvfio-user.c.o.d -o lib/libvfio-user.a.p/libvfio-user.c.o -c ../../../libvfio-user/lib/libvfio-user.c
../../../libvfio-user/lib/libvfio-user.c: In function ‘handle_device_get_region_io_fds’:
../../../libvfio-user/lib/libvfio-user.c:658:38: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  658 |         msg->out.fds = calloc(sizeof(int),
      |                                      ^~~
../../../libvfio-user/lib/libvfio-user.c:658:38: note: earlier argument should specify number of elements, later size of each element
cc1: all warnings being treated as errors
[28/36] Compiling C object test/unit_tests.p/.._lib_libvfio-user.c.o
FAILED: test/unit_tests.p/.._lib_libvfio-user.c.o
cc -Itest/unit_tests.p -Itest -I../../../libvfio-user/test -Iinclude -I../../../libvfio-user/include -Ilib -I../../../libvfio-user/lib -I/usr/include/json-c -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu99 -O0 -g -gdwarf-4 -DUNIT_TEST -DWITH_TRAN_PIPE -D_GNU_SOURCE -Werror -DDEBUG -Wno-missing-field-initializers -Wmissing-declarations -Wwrite-strings -MD -MQ test/unit_tests.p/.._lib_libvfio-user.c.o -MF test/unit_tests.p/.._lib_libvfio-user.c.o.d -o test/unit_tests.p/.._lib_libvfio-user.c.o -c ../../../libvfio-user/lib/libvfio-user.c
../../../libvfio-user/lib/libvfio-user.c: In function ‘handle_device_get_region_io_fds’:
../../../libvfio-user/lib/libvfio-user.c:658:38: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  658 |         msg->out.fds = calloc(sizeof(int),
      |                                      ^~~
../../../libvfio-user/lib/libvfio-user.c:658:38: note: earlier argument should specify number of elements, later size of each element
cc1: all warnings being treated as errors
ninja: build stopped: subcommand failed.
make[1]: *** [Makefile:21: build] Error 1
make: *** [/root/spdk/mk/spdk.subdirs.mk:16: vfiouserbuild] Error 2
make: *** Waiting for unfinished jobs....

This currently affects SPDK builds under fedora40 (as it uses libvfio-user as a submodule, currently pointing at the aforementioned commit). Something like this seems to help:

diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c
index 94524a2..3564fbb 100644
--- a/lib/libvfio-user.c
+++ b/lib/libvfio-user.c
@@ -655,8 +655,7 @@ handle_device_get_region_io_fds(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg)

     msg->out.nr_fds = 0;
     if (req->argsz >= reply->argsz) {
-        msg->out.fds = calloc(sizeof(int),
-                              max_sent_sub_regions + nr_shadow_reg);
+        msg->out.fds = calloc(max_sent_sub_regions + nr_shadow_reg, sizeof(int));
         if (msg->out.fds == NULL) {
             return -1;
         }
jlevon commented 3 months ago

Thanks for the bug report, can I talk you into raising a PR with a Signed-off-by line?

mikeBashStuff commented 3 months ago

@jlevon Here you go: https://github.com/nutanix/libvfio-user/pull/802