Skip to content

Commit

Permalink
Fix a number of benign compiler warnings on Linux/GCC (#805)
Browse files Browse the repository at this point in the history
src/recv.c:103:17: warning: ‘static’ is not at beginning of declaration [-Wold-style-declaration]
  103 |                 const static uint32_t available_space = sizeof(fake_eth_hdr) - sizeof(struct ether_header);
      |                 ^~~~~

src/if-netmap-linux.c: In function ‘fetch_stats64’:
src/if-netmap-linux.c:94:18: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic]
   94 |                 };
      |                  ^

src/probe_modules/packet.h: In function ‘check_dst_port’:
src/probe_modules/packet.h:162:37: warning: suggest parentheses around comparison in operand of ‘^’ -Wparentheses]
  162 |                 return (to_validate <= max ^ to_validate >= min);
      |                         ~~~~~~~~~~~~^~~~~~

src/probe_modules/packet.c: In function ‘set_timestamp_option_with_nops’:
src/probe_modules/packet.c:178:24: warning: implicit declaration of function ‘time’ [-Wimplicit-function-declaration]
  178 |         uint32_t now = time(NULL);
      |                        ^~~~
src/probe_modules/packet.c:178:24: warning: nested extern declaration of ‘time’ [-Wnested-externs]
  178 |         uint32_t now = time(NULL);
      |                        ^~~~
  • Loading branch information
droe committed Mar 3, 2024
1 parent ea5f260 commit 4c36736
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/if-netmap-linux.c
Expand Up @@ -91,15 +91,15 @@ fetch_stats64(struct rtnl_link_stats64 *rtlstats64, char const *ifname, int nlrt
struct {
struct nlmsgerr nlerr;
} err;
};
} u;
} nlresp;
_Static_assert(sizeof(nlresp.ans) >= sizeof(nlresp.err));
static const size_t ans_size = offsetof(struct nlresp, ans) + sizeof(nlresp.ans);
static const size_t err_size = offsetof(struct nlresp, err) + sizeof(nlresp.err);
_Static_assert(sizeof(nlresp.u.ans) >= sizeof(nlresp.u.err));
static const size_t ans_size = offsetof(struct nlresp, u.ans) + sizeof(nlresp.u.ans);
static const size_t err_size = offsetof(struct nlresp, u.err) + sizeof(nlresp.u.err);

memset(iov, 0, sizeof(iov));
iov[0].iov_base = (void *)&nlresp;
iov[0].iov_len = offsetof(struct nlresp, ans.rtlstats64);
iov[0].iov_len = offsetof(struct nlresp, u.ans.rtlstats64);
iov[1].iov_base = (void *)rtlstats64; // caller-provided
iov[1].iov_len = sizeof(struct rtnl_link_stats64);
memset(&msg, 0, sizeof(msg));
Expand All @@ -116,9 +116,9 @@ fetch_stats64(struct rtnl_link_stats64 *rtlstats64, char const *ifname, int nlrt

if (nlresp.nlh.nlmsg_type == NLMSG_ERROR) {
// copy second iov into ans in first iov to get contiguous struct nlmsgerr
nlresp.ans.rtlstats64 = *rtlstats64;
assert(nlresp.err.nlerr.error < 0);
errno = -nlresp.err.nlerr.error;
nlresp.u.ans.rtlstats64 = *rtlstats64;
assert(nlresp.u.err.nlerr.error < 0);
errno = -nlresp.u.err.nlerr.error;
log_fatal("if-netmap-linux", "received NLMSG_ERROR: %d: %s", errno, strerror(errno));
}
if (nlresp.nlh.nlmsg_type != RTM_NEWSTATS) {
Expand Down
1 change: 1 addition & 0 deletions src/probe_modules/packet.c
Expand Up @@ -10,6 +10,7 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <time.h>

#include "../../lib/includes.h"
#include "../../lib/xalloc.h"
Expand Down
2 changes: 1 addition & 1 deletion src/probe_modules/packet.h
Expand Up @@ -159,7 +159,7 @@ static inline int check_dst_port(uint16_t port, int num_ports,
if (min <= max) {
return (to_validate <= max && to_validate >= min);
} else {
return (to_validate <= max ^ to_validate >= min);
return ((to_validate <= max) != (to_validate >= min));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/recv.c
Expand Up @@ -100,7 +100,7 @@ void handle_packet(uint32_t buflen, const u_char *bytes,
// Here, we fake an ethernet frame (which is initialized to
// have ETH_P_IP proto and 00s for dest/src).
if (zconf.send_ip_pkts) {
const static uint32_t available_space = sizeof(fake_eth_hdr) - sizeof(struct ether_header);
static const uint32_t available_space = sizeof(fake_eth_hdr) - sizeof(struct ether_header);
assert(buflen > (uint32_t)zconf.data_link_size);
buflen -= zconf.data_link_size;
if (buflen > available_space) {
Expand Down

0 comments on commit 4c36736

Please sign in to comment.