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

Fix a number of benign compiler warnings on Linux/GCC #805

Merged
merged 1 commit into from Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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