lxi-tools / liblxi

Open source LXI library
https://lxi-tools.github.io
Other
103 stars 27 forks source link

warning: cast between incompatible function types #33

Closed janhenke closed 1 year ago

janhenke commented 1 year ago

Hi,

while packaging this for Gentoo, I noticed a compiler warning with 1.18:

[4/8] x86_64-pc-linux-gnu-gcc -Isrc/liblxi.so.1.0.0.p -Isrc -I../liblxi-1.18/src -I/usr/include/tirpc -I/usr/include/libxml2 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O2 -DHAVE_AVAHI -march=native -O2 -pipe -fPIC -pthread -D_REENTRANT -Wno-unused-variable -Wno-unused-parameter -Wno-unused-result -fvisibility=hidden -D_GNU_SOURCE -MD -MQ src/liblxi.so.1.0.0.p/vxi11core_clnt.c.o -MF src/liblxi.so.1.0.0.p/vxi11core_clnt.c.o.d -o src/liblxi.so.1.0.0.p/vxi11core_clnt.c.o -c ../liblxi-1.18/src/vxi11core_clnt.c
In file included from /usr/include/tirpc/rpc/rpc.h:49,
                 from ../liblxi-1.18/src/vxi11core.h:9,
                 from ../liblxi-1.18/src/vxi11core_clnt.c:7:
../liblxi-1.18/src/vxi11core_clnt.c: In function ‘destroy_intr_chan_1’:
../liblxi-1.18/src/vxi11core_clnt.c:151:17: warning: cast between incompatible function types from ‘bool_t (*)(void)’ {aka ‘int (*)(void)’} to ‘bool_t (*)(XDR *, ...)’ {aka ‘int (*)(struct __rpc_xdr *, ...)’} [-Wcast-function-type]
  151 |                 (xdrproc_t) xdr_void, (caddr_t) argp,
      |                 ^
/usr/include/tirpc/rpc/clnt.h:166:45: note: in definition of macro ‘clnt_call’
  166 |         ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
      |  

Could you look into that and fix it?

lundmar commented 1 year ago

Yeah, it's been there for a while. The only reason that I have not put in any effort to fix the code is because the warning is in code auto generated by rpcgen from the vxi11core.rpcl file. In fact, the header of the source file says " Please do not edit this file. It was generated using rpcgen.".

This code has been in production for decades now on many different platforms so I'm not too worried about its correctness. By closer inspection, the code is related to the (clnt_call) rpc call which destructs an interrupt channel and takes as parameter a function pointer to xdr_void which does not have the expected prototype. However, this is just an address to a pointer function so it will only cause a problem on the call stack when invoked on the remote side but in case of destroying the channel it is not called so no problem. The original vxi11core.rpcl is very explicit about the definition of this rpc call.

However, since you noticed the warning I will simply go ahead and suppress it using pragmas. It is fixed in a2004b2f69b3053b0751bd5ba853930e07570002