From 0f679438f36d8c2a31dfe490007e983b085caef6 Mon Sep 17 00:00:00 2001 From: Petr Vaněk Date: Mon, 6 Mar 2023 11:19:30 +0100 Subject: Printf test suite fails on systems with musl libc because tests for "%m" and "%M" formats expect "Input/output error" message but musl returns "I/O error". Proposed change compares the printf output with string returned from strerror function for EIO constant. See-also: https://bugs.gentoo.org/836713 Minor change from committer. --- lib/printf_test.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/printf_test.c b/lib/printf_test.c index 47ea905d..88ecf05e 100644 --- a/lib/printf_test.c +++ b/lib/printf_test.c @@ -32,11 +32,14 @@ t_simple(void) BSPRINTF(1, "@", buf, "@", 64); BSPRINTF(1, "\xff", buf, "%c", 0xff); - errno = 5; - BSPRINTF(18, "Input/output error", buf, "%m"); + const char *io_error_str = lp_strdup(tmp_linpool, strerror(EIO)); + const int io_error_len = strlen(io_error_str); + + errno = EIO; + BSPRINTF(io_error_len, io_error_str, buf, "%m"); errno = 0; - BSPRINTF(18, "Input/output error", buf, "%M", 5); + BSPRINTF(io_error_len, io_error_str, buf, "%M", EIO); BSPRINTF(11, "TeSt%StRiNg", buf, "%s", "TeSt%StRiNg"); -- cgit v1.2.3 From 6b38285f587be9d4b128ae816bc25cb338f7f07c Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Mon, 6 Mar 2023 11:57:40 +0100 Subject: Net: Replace runtime checks with STATIC_ASSERT() --- lib/net.c | 32 +++++++++++++------------------- lib/net.h | 2 -- sysdep/unix/main.c | 1 - 3 files changed, 13 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/net.c b/lib/net.c index 976ddbcc..289a4297 100644 --- a/lib/net.c +++ b/lib/net.c @@ -57,6 +57,19 @@ const u16 net_max_text_length[] = { [NET_MPLS] = 7, /* "1048575" */ }; +/* There should be no implicit padding in net_addr structures */ +STATIC_ASSERT(sizeof(net_addr) == 24); +STATIC_ASSERT(sizeof(net_addr_ip4) == 8); +STATIC_ASSERT(sizeof(net_addr_ip6) == 20); +STATIC_ASSERT(sizeof(net_addr_vpn4) == 16); +STATIC_ASSERT(sizeof(net_addr_vpn6) == 32); +STATIC_ASSERT(sizeof(net_addr_roa4) == 16); +STATIC_ASSERT(sizeof(net_addr_roa6) == 28); +STATIC_ASSERT(sizeof(net_addr_flow4) == 8); +STATIC_ASSERT(sizeof(net_addr_flow6) == 20); +STATIC_ASSERT(sizeof(net_addr_ip6_sadr) == 40); +STATIC_ASSERT(sizeof(net_addr_mpls) == 8); + int rd_format(const u64 rd, char *buf, int buflen) @@ -310,22 +323,3 @@ net_in_netX(const net_addr *a, const net_addr *n) return (net_pxlen(n) <= net_pxlen(a)) && ipa_in_netX(net_prefix(a), n); } - -#define CHECK_NET(T,S) \ - ({ if (sizeof(T) != S) die("sizeof %s is %d/%d", #T, (int) sizeof(T), S); }) - -void -net_init(void) -{ - CHECK_NET(net_addr, 24); - CHECK_NET(net_addr_ip4, 8); - CHECK_NET(net_addr_ip6, 20); - CHECK_NET(net_addr_vpn4, 16); - CHECK_NET(net_addr_vpn6, 32); - CHECK_NET(net_addr_roa4, 16); - CHECK_NET(net_addr_roa6, 28); - CHECK_NET(net_addr_flow4, 8); - CHECK_NET(net_addr_flow6, 20); - CHECK_NET(net_addr_ip6_sadr, 40); - CHECK_NET(net_addr_mpls, 8); -} diff --git a/lib/net.h b/lib/net.h index 9f4a00ad..da7254c2 100644 --- a/lib/net.h +++ b/lib/net.h @@ -620,6 +620,4 @@ static inline int net_in_net_src_ip6_sadr(const net_addr_ip6_sadr *a, const net_ int ipa_in_netX(const ip_addr A, const net_addr *N); int net_in_netX(const net_addr *A, const net_addr *N); -void net_init(void); - #endif diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index 627d7a4a..0d3ec0c0 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -889,7 +889,6 @@ main(int argc, char **argv) log_switch(1, NULL, NULL); random_init(); - net_init(); resource_init(); timer_init(); olock_init(); -- cgit v1.2.3