Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mikeBashStuff opened this issue Aug 14, 2024 · 2 comments · Fixed by #802
Closed

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

mikeBashStuff opened this issue Aug 14, 2024 · 2 comments · Fixed by #802

Comments

@mikeBashStuff
Copy link
Contributor

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
Copy link
Collaborator

jlevon commented Aug 14, 2024

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

mikeBashStuff added a commit to mikeBashStuff/libvfio-user that referenced this issue Aug 16, 2024
Fixes issue nutanix#801.

Signed-off-by: Michal Berger <michal.berger@intel.com>
@mikeBashStuff
Copy link
Contributor Author

@jlevon Here you go: #802

jlevon pushed a commit to mikeBashStuff/libvfio-user that referenced this issue Aug 16, 2024
Fixes issue nutanix#801.

Signed-off-by: Michal Berger <michal.berger@intel.com>
jlevon pushed a commit that referenced this issue Aug 16, 2024
)

Fixes issue #801.

Signed-off-by: Michal Berger <michal.berger@intel.com>
jlevon pushed a commit that referenced this issue Aug 16, 2024
)

Fixes issue #801.

Signed-off-by: Michal Berger <michal.berger@intel.com>
(cherry picked from commit a5fca05)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants