-
Notifications
You must be signed in to change notification settings - Fork 908
Description
fxlb commented 3 days ago •
Many warnings with clang-16:
pcap-dpdk.c:335:15: warning: variable 'gather_len' set but not used [-Wunused-but-set-variable]
unsigned int gather_len =0;
^
pcap-dpdk.c:474:32: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int') [-Wshorten-64-to-32]
ps->ps_recv = pd->curr_stats.ipackets;
~ ~~~~~~~~~~~~~~~^~~~~~~~
pcap-dpdk.c:475:32: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int') [-Wshorten-64-to-32]
ps->ps_drop = pd->curr_stats.ierrors;
~ ~~~~~~~~~~~~~~~^~~~~~~
pcap-dpdk.c:477:34: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int') [-Wshorten-64-to-32]
ps->ps_ifdrop = pd->curr_stats.imissed;
~ ~~~~~~~~~~~~~~~^~~~~~~
pcap-dpdk.c:550:13: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
for (int i=prefix_len; device[i]; i++){
~ ^~~~~~~~~~
@fxlb
Member
fxlb commented 3 days ago
Other warnings with GCC 12.2:
pcap-dpdk.c: In function 'pcap_dpdk_activate':
pcap-dpdk.c:785:52: warning: '%s' directive output may be truncated writing up to 255 bytes into a region of size 236 [-Wformat-truncation=]
785 | "Can't open device %s: %s",
| ^~
786 | p->opt.device, dpdk_pre_init_errbuf);
| ~~~~~~~~~~~~~~~~~~~~
pcap-dpdk.c:784:25: note: 'snprintf' output 21 or more bytes (assuming 276) into a destination of size 256
784 | snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
785 | "Can't open device %s: %s",
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
786 | p->opt.device, dpdk_pre_init_errbuf);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pcap-dpdk.c: In function 'pcap_dpdk_findalldevs':
pcap-dpdk.c:1037:59: warning: '%s' directive output may be truncated writing up to 255 bytes into a region of size 227 [-Wformat-truncation=]
1037 | "Can't look for DPDK devices: %s",
| ^~
1038 | dpdk_pre_init_errbuf);
| ~~~~~~~~~~~~~~~~~~~~
pcap-dpdk.c:1036:25: note: 'snprintf' output between 30 and 285 bytes into a destination of size 256
1036 | snprintf(ebuf, PCAP_ERRBUF_SIZE,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1037 | "Can't look for DPDK devices: %s",
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1038 | dpdk_pre_init_errbuf);
| ~~~~~~~~~~~~~~~~~~~~~
@idogoshen
Contributor
Author
idogoshen commented 3 days ago
@fxlb This are “old” warnings and not related to this patch
Attached make output for latest release 1.10.5 with same warnings
@fxlb
Member
fxlb commented 3 days ago
OK. Could a DPDK expert fix these warnings and perform non-regression testing?
@guyharris
Member
guyharris commented 2 days ago
Many warnings with clang-16:
pcap-dpdk.c:335:15: warning: variable 'gather_len' set but not used [-Wunused-but-set-variable]
unsigned int gather_len =0;
^
pcap-dpdk.c:474:32: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int') [-Wshorten-64-to-32]
ps->ps_recv = pd->curr_stats.ipackets;
~ ~~~~~~~~~~~~~~~^~~~~~~~
pcap-dpdk.c:475:32: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int') [-Wshorten-64-to-32]
ps->ps_drop = pd->curr_stats.ierrors;
~ ~~~~~~~~~~~~~~~^~~~~~~
pcap-dpdk.c:477:34: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int') [-Wshorten-64-to-32]
ps->ps_ifdrop = pd->curr_stats.imissed;
~ ~~~~~~~~~~~~~~~^~~~~~~
pcap-dpdk.c:550:13: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
for (int i=prefix_len; device[i]; i++){
~ ^~~~~~~~~~
Ultimately, this requires a new API for getting capture statistics that uses 64-bit numbers. (That API should probably supply the equivalent of a pcapNowGeneric Interface Statistics Block; that would make it easier to add new statistics and to indicate which statistics are, and aren't, available.)
In the short term, we should probably just cast the statistics to bpf_u_int32. (I don't know what code using libpcap would break if we use C99 integer types and included <stdtypes.h> in pcap.h.)
@guyharris
Member
guyharris commented 2 days ago
Other warnings with GCC 12.2:
pcap-dpdk.c: In function 'pcap_dpdk_activate':
pcap-dpdk.c:785:52: warning: '%s' directive output may be truncated writing up to 255 bytes into a region of size 236 [-Wformat-truncation=]
785 | "Can't open device %s: %s",
| ^~
786 | p->opt.device, dpdk_pre_init_errbuf);
| ~~~~~~~~~~~~~~~~~~~~
pcap-dpdk.c:784:25: note: 'snprintf' output 21 or more bytes (assuming 276) into a destination of size 256
784 | snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
785 | "Can't open device %s: %s",
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
786 | p->opt.device, dpdk_pre_init_errbuf);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pcap-dpdk.c: In function 'pcap_dpdk_findalldevs':
pcap-dpdk.c:1037:59: warning: '%s' directive output may be truncated writing up to 255 bytes into a region of size 227 [-Wformat-truncation=]
1037 | "Can't look for DPDK devices: %s",
| ^~
1038 | dpdk_pre_init_errbuf);
| ~~~~~~~~~~~~~~~~~~~~
pcap-dpdk.c:1036:25: note: 'snprintf' output between 30 and 285 bytes into a destination of size 256
1036 | snprintf(ebuf, PCAP_ERRBUF_SIZE,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1037 | "Can't look for DPDK devices: %s",
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1038 | dpdk_pre_init_errbuf);
| ~~~~~~~~~~~~~~~~~~~~~
This one really needs us to have a new API that returns un-truncated error message strings. We'd use pcapint_asprintf() to generate error strings and store a pointer to the last error string in the pcap_t, have pcap_geterr_long() (or whatever its name is) return an untruncated error string, and have pcap_geterr() copy the saved error string to the fixed-length buffer (and make sure it doesn't truncate any UTF-8 strings).