passt: Address new clang-tidy warnings from LLVM 13.0.1
clang-tidy from LLVM 13.0.1 reports some new warnings from these checkers: - altera-unroll-loops, altera-id-dependent-backward-branch: ignore for the moment being, add a TODO item - bugprone-easily-swappable-parameters: ignore, nothing to do about those - readability-function-cognitive-complexity: ignore for the moment being, add a TODO item - altera-struct-pack-align: ignore, alignment is forced in protocol headers - concurrency-mt-unsafe: ignore for the moment being, add a TODO item Fix bugprone-implicit-widening-of-multiplication-result warnings, though, that's doable and they seem to make sense. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
20d271b226
commit
292c185553
9 changed files with 52 additions and 25 deletions
24
Makefile
24
Makefile
|
@ -167,6 +167,23 @@ pkgs:
|
||||||
#
|
#
|
||||||
# - bugprone-suspicious-string-compare
|
# - bugprone-suspicious-string-compare
|
||||||
# Return value of memcmp(), not really suspicious
|
# Return value of memcmp(), not really suspicious
|
||||||
|
#
|
||||||
|
# - altera-unroll-loops
|
||||||
|
# - altera-id-dependent-backward-branch
|
||||||
|
# TODO: check paths where it might make sense to improve performance
|
||||||
|
#
|
||||||
|
# - bugprone-easily-swappable-parameters
|
||||||
|
# Not much can be done about them other than being careful
|
||||||
|
#
|
||||||
|
# - readability-function-cognitive-complexity
|
||||||
|
# TODO: split reported functions
|
||||||
|
#
|
||||||
|
# - altera-struct-pack-align
|
||||||
|
# "Poor" alignment needed for structs reflecting message formats/headers
|
||||||
|
#
|
||||||
|
# - concurrency-mt-unsafe
|
||||||
|
# TODO: check again if multithreading is implemented
|
||||||
|
|
||||||
clang-tidy: $(wildcard *.c) $(wildcard *.h)
|
clang-tidy: $(wildcard *.c) $(wildcard *.h)
|
||||||
clang-tidy -checks=*,-modernize-*,\
|
clang-tidy -checks=*,-modernize-*,\
|
||||||
-clang-analyzer-valist.Uninitialized,\
|
-clang-analyzer-valist.Uninitialized,\
|
||||||
|
@ -187,7 +204,12 @@ clang-tidy: $(wildcard *.c) $(wildcard *.h)
|
||||||
-bugprone-narrowing-conversions,\
|
-bugprone-narrowing-conversions,\
|
||||||
-cppcoreguidelines-narrowing-conversions,\
|
-cppcoreguidelines-narrowing-conversions,\
|
||||||
-cppcoreguidelines-avoid-non-const-global-variables,\
|
-cppcoreguidelines-avoid-non-const-global-variables,\
|
||||||
-bugprone-suspicious-string-compare \
|
-bugprone-suspicious-string-compare,\
|
||||||
|
-altera-unroll-loops,-altera-id-dependent-backward-branch,\
|
||||||
|
-bugprone-easily-swappable-parameters,\
|
||||||
|
-readability-function-cognitive-complexity,\
|
||||||
|
-altera-struct-pack-align,\
|
||||||
|
-concurrency-mt-unsafe \
|
||||||
--warnings-as-errors=* $(wildcard *.c) -- $(CFLAGS)
|
--warnings-as-errors=* $(wildcard *.c) -- $(CFLAGS)
|
||||||
|
|
||||||
ifeq ($(shell $(CC) -v 2>&1 | grep -c "gcc version"),1)
|
ifeq ($(shell $(CC) -v 2>&1 | grep -c "gcc version"),1)
|
||||||
|
|
|
@ -108,10 +108,13 @@ uint16_t csum_unaligned(const void *buf, size_t len, uint32_t init)
|
||||||
*/
|
*/
|
||||||
void csum_tcp4(struct iphdr *iph)
|
void csum_tcp4(struct iphdr *iph)
|
||||||
{
|
{
|
||||||
struct tcphdr *th = (struct tcphdr *)((char *)iph + iph->ihl * 4);
|
uint16_t tlen = ntohs(iph->tot_len) - iph->ihl * 4, *p;
|
||||||
uint16_t tlen = ntohs(iph->tot_len) - iph->ihl * 4, *p = (uint16_t *)th;
|
struct tcphdr *th;
|
||||||
uint32_t sum = 0;
|
uint32_t sum = 0;
|
||||||
|
|
||||||
|
th = (struct tcphdr *)((char *)iph + (intptr_t)(iph->ihl * 4));
|
||||||
|
p = (uint16_t *)th;
|
||||||
|
|
||||||
sum += (iph->saddr >> 16) & 0xffff;
|
sum += (iph->saddr >> 16) & 0xffff;
|
||||||
sum += iph->saddr & 0xffff;
|
sum += iph->saddr & 0xffff;
|
||||||
sum += (iph->daddr >> 16) & 0xffff;
|
sum += (iph->daddr >> 16) & 0xffff;
|
||||||
|
|
4
conf.c
4
conf.c
|
@ -867,7 +867,7 @@ void conf(struct ctx *c, int argc, char **argv)
|
||||||
|
|
||||||
for (i = 0; i < ETH_ALEN; i++) {
|
for (i = 0; i < ETH_ALEN; i++) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
b = strtol(optarg + i * 3, NULL, 16);
|
b = strtol(optarg + (intptr_t)i * 3, NULL, 16);
|
||||||
if (b < 0 || b > UCHAR_MAX || errno) {
|
if (b < 0 || b > UCHAR_MAX || errno) {
|
||||||
err("Invalid MAC address: %s", optarg);
|
err("Invalid MAC address: %s", optarg);
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
@ -1032,7 +1032,7 @@ void conf(struct ctx *c, int argc, char **argv)
|
||||||
case 'M':
|
case 'M':
|
||||||
for (i = 0; i < ETH_ALEN; i++) {
|
for (i = 0; i < ETH_ALEN; i++) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
b = strtol(optarg + i * 3, NULL, 16);
|
b = strtol(optarg + (intptr_t)i * 3, NULL, 16);
|
||||||
if (b < 0 || b > UCHAR_MAX || errno) {
|
if (b < 0 || b > UCHAR_MAX || errno) {
|
||||||
err("Invalid MAC address: %s", optarg);
|
err("Invalid MAC address: %s", optarg);
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
|
8
dhcp.c
8
dhcp.c
|
@ -271,10 +271,10 @@ int dhcp(struct ctx *c, struct ethhdr *eh, size_t len)
|
||||||
if (len < sizeof(*eh) + sizeof(*iph))
|
if (len < sizeof(*eh) + sizeof(*iph))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (len < sizeof(*eh) + iph->ihl * 4 + sizeof(*uh))
|
if (len < sizeof(*eh) + (long)iph->ihl * 4 + sizeof(*uh))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
uh = (struct udphdr *)((char *)iph + iph->ihl * 4);
|
uh = (struct udphdr *)((char *)iph + (long)(iph->ihl * 4));
|
||||||
m = (struct msg *)(uh + 1);
|
m = (struct msg *)(uh + 1);
|
||||||
|
|
||||||
if (uh->dest != htons(67))
|
if (uh->dest != htons(67))
|
||||||
|
@ -283,7 +283,7 @@ int dhcp(struct ctx *c, struct ethhdr *eh, size_t len)
|
||||||
if (c->no_dhcp)
|
if (c->no_dhcp)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
mlen = len - sizeof(*eh) - iph->ihl * 4 - sizeof(*uh);
|
mlen = len - sizeof(*eh) - (long)iph->ihl * 4 - sizeof(*uh);
|
||||||
if (mlen != ntohs(uh->len) - sizeof(*uh) ||
|
if (mlen != ntohs(uh->len) - sizeof(*uh) ||
|
||||||
mlen < offsetof(struct msg, o) ||
|
mlen < offsetof(struct msg, o) ||
|
||||||
m->op != BOOTREQUEST)
|
m->op != BOOTREQUEST)
|
||||||
|
@ -349,7 +349,7 @@ int dhcp(struct ctx *c, struct ethhdr *eh, size_t len)
|
||||||
iph->daddr = c->addr4;
|
iph->daddr = c->addr4;
|
||||||
iph->saddr = c->gw4;
|
iph->saddr = c->gw4;
|
||||||
iph->check = 0;
|
iph->check = 0;
|
||||||
iph->check = csum_unaligned(iph, iph->ihl * 4, 0);
|
iph->check = csum_unaligned(iph, (intptr_t)(iph->ihl * 4), 0);
|
||||||
|
|
||||||
len += sizeof(*eh);
|
len += sizeof(*eh);
|
||||||
memcpy(eh->h_dest, eh->h_source, ETH_ALEN);
|
memcpy(eh->h_dest, eh->h_source, ETH_ALEN);
|
||||||
|
|
2
qrap.c
2
qrap.c
|
@ -111,7 +111,7 @@ void usage(const char *name)
|
||||||
*/
|
*/
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct timeval tv = { .tv_sec = 0, .tv_usec = 500 * 1000 };
|
struct timeval tv = { .tv_sec = 0, .tv_usec = (long)(500 * 1000) };
|
||||||
int i, s, qemu_argc = 0, addr_map = 0, has_dev = 0;
|
int i, s, qemu_argc = 0, addr_map = 0, has_dev = 0;
|
||||||
char *qemu_argv[ARG_MAX], dev_str[ARG_MAX];
|
char *qemu_argv[ARG_MAX], dev_str[ARG_MAX];
|
||||||
struct sockaddr_un addr = {
|
struct sockaddr_un addr = {
|
||||||
|
|
8
tap.c
8
tap.c
|
@ -131,7 +131,7 @@ void tap_ip_send(struct ctx *c, struct in6_addr *src, uint8_t proto,
|
||||||
memcpy(&iph->saddr, &src->s6_addr[12], 4);
|
memcpy(&iph->saddr, &src->s6_addr[12], 4);
|
||||||
|
|
||||||
iph->check = 0;
|
iph->check = 0;
|
||||||
iph->check = csum_unaligned(iph, iph->ihl * 4, 0);
|
iph->check = csum_unaligned(iph, (size_t)iph->ihl * 4, 0);
|
||||||
|
|
||||||
memcpy(data, in, len);
|
memcpy(data, in, len);
|
||||||
|
|
||||||
|
@ -337,9 +337,9 @@ resume:
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
iph = (struct iphdr *)(eh + 1);
|
iph = (struct iphdr *)(eh + 1);
|
||||||
if ((iph->ihl * 4) + sizeof(*eh) > len)
|
if ((size_t)iph->ihl * 4 + sizeof(*eh) > len)
|
||||||
continue;
|
continue;
|
||||||
if (iph->ihl * 4 < (int)sizeof(*iph))
|
if ((size_t)iph->ihl * 4 < (int)sizeof(*iph))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (iph->saddr && c->addr4_seen != iph->saddr) {
|
if (iph->saddr && c->addr4_seen != iph->saddr) {
|
||||||
|
@ -347,7 +347,7 @@ resume:
|
||||||
proto_update_l2_buf(NULL, NULL, &c->addr4_seen);
|
proto_update_l2_buf(NULL, NULL, &c->addr4_seen);
|
||||||
}
|
}
|
||||||
|
|
||||||
l4h = (char *)iph + iph->ihl * 4;
|
l4h = (char *)iph + (size_t)iph->ihl * 4;
|
||||||
l4_len = len - ((intptr_t)l4h - (intptr_t)eh);
|
l4_len = len - ((intptr_t)l4h - (intptr_t)eh);
|
||||||
|
|
||||||
if (iph->protocol == IPPROTO_ICMP) {
|
if (iph->protocol == IPPROTO_ICMP) {
|
||||||
|
|
10
tcp.c
10
tcp.c
|
@ -345,7 +345,7 @@
|
||||||
|
|
||||||
#define TCP_TAP_FRAMES 256
|
#define TCP_TAP_FRAMES 256
|
||||||
|
|
||||||
#define MAX_PIPE_SIZE (2 * 1024 * 1024)
|
#define MAX_PIPE_SIZE (2UL * 1024 * 1024)
|
||||||
|
|
||||||
#define TCP_HASH_TABLE_LOAD 70 /* % */
|
#define TCP_HASH_TABLE_LOAD 70 /* % */
|
||||||
#define TCP_HASH_TABLE_SIZE (MAX_TAP_CONNS * 100 / \
|
#define TCP_HASH_TABLE_SIZE (MAX_TAP_CONNS * 100 / \
|
||||||
|
@ -1040,8 +1040,8 @@ static int tcp_opt_get(struct tcphdr *th, size_t len, uint8_t type_search,
|
||||||
uint8_t type, optlen;
|
uint8_t type, optlen;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if (len > (unsigned)th->doff * 4)
|
if (len > (size_t)th->doff * 4)
|
||||||
len = th->doff * 4;
|
len = (size_t)th->doff * 4;
|
||||||
|
|
||||||
len -= sizeof(*th);
|
len -= sizeof(*th);
|
||||||
p = (char *)(th + 1);
|
p = (char *)(th + 1);
|
||||||
|
@ -1568,7 +1568,7 @@ static int tcp_update_seqack_wnd(struct ctx *c, struct tcp_tap_conn *conn,
|
||||||
#else
|
#else
|
||||||
if (conn->state > ESTABLISHED || (flags & (DUP_ACK | FORCE_ACK)) ||
|
if (conn->state > ESTABLISHED || (flags & (DUP_ACK | FORCE_ACK)) ||
|
||||||
conn->local || tcp_rtt_dst_low(conn) ||
|
conn->local || tcp_rtt_dst_low(conn) ||
|
||||||
conn->snd_buf < SNDBUF_SMALL) {
|
(unsigned long)conn->snd_buf < SNDBUF_SMALL) {
|
||||||
conn->seq_ack_to_tap = conn->seq_from_tap;
|
conn->seq_ack_to_tap = conn->seq_from_tap;
|
||||||
} else if (conn->seq_ack_to_tap != conn->seq_from_tap) {
|
} else if (conn->seq_ack_to_tap != conn->seq_from_tap) {
|
||||||
if (!tinfo) {
|
if (!tinfo) {
|
||||||
|
@ -2393,7 +2393,7 @@ static void tcp_data_from_tap(struct ctx *c, struct tcp_tap_conn *conn,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
off = th->doff * 4;
|
off = (size_t)th->doff * 4;
|
||||||
if (off < sizeof(*th) || off > len) {
|
if (off < sizeof(*th) || off > len) {
|
||||||
tcp_rst(c, conn);
|
tcp_rst(c, conn);
|
||||||
return;
|
return;
|
||||||
|
|
8
util.c
8
util.c
|
@ -51,7 +51,7 @@ void name(const char *format, ...) { \
|
||||||
clock_gettime(CLOCK_REALTIME, &tp); \
|
clock_gettime(CLOCK_REALTIME, &tp); \
|
||||||
fprintf(stderr, "%li.%04li: ", \
|
fprintf(stderr, "%li.%04li: ", \
|
||||||
tp.tv_sec - log_debug_start, \
|
tp.tv_sec - log_debug_start, \
|
||||||
tp.tv_nsec / (100 * 1000)); \
|
tp.tv_nsec / (100L * 1000)); \
|
||||||
} else { \
|
} else { \
|
||||||
va_start(args, format); \
|
va_start(args, format); \
|
||||||
passt_vsyslog(level, format, args); \
|
passt_vsyslog(level, format, args); \
|
||||||
|
@ -305,12 +305,14 @@ void sock_probe_mem(struct ctx *c)
|
||||||
|
|
||||||
sl = sizeof(v);
|
sl = sizeof(v);
|
||||||
if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, &v, sizeof(v)) ||
|
if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, &v, sizeof(v)) ||
|
||||||
getsockopt(s, SOL_SOCKET, SO_SNDBUF, &v, &sl) || v < SNDBUF_BIG)
|
getsockopt(s, SOL_SOCKET, SO_SNDBUF, &v, &sl) ||
|
||||||
|
(size_t)v < SNDBUF_BIG)
|
||||||
c->low_wmem = 1;
|
c->low_wmem = 1;
|
||||||
|
|
||||||
v = INT_MAX / 2;
|
v = INT_MAX / 2;
|
||||||
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &v, sizeof(v)) ||
|
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &v, sizeof(v)) ||
|
||||||
getsockopt(s, SOL_SOCKET, SO_RCVBUF, &v, &sl) || v < RCVBUF_BIG)
|
getsockopt(s, SOL_SOCKET, SO_RCVBUF, &v, &sl) ||
|
||||||
|
(size_t)v < RCVBUF_BIG)
|
||||||
c->low_rmem = 1;
|
c->low_rmem = 1;
|
||||||
|
|
||||||
close(s);
|
close(s);
|
||||||
|
|
6
util.h
6
util.h
|
@ -144,9 +144,9 @@ enum {
|
||||||
.daddr = IN6ADDR_ANY_INIT, \
|
.daddr = IN6ADDR_ANY_INIT, \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RCVBUF_BIG (2 * 1024 * 1024)
|
#define RCVBUF_BIG (2UL * 1024 * 1024)
|
||||||
#define SNDBUF_BIG (4 * 1024 * 1024)
|
#define SNDBUF_BIG (4UL * 1024 * 1024)
|
||||||
#define SNDBUF_SMALL (128 * 1024)
|
#define SNDBUF_SMALL (128UL * 1024)
|
||||||
|
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
Loading…
Reference in a new issue