From 378febffff2d52aac202f52391ad00fa83fa5b38 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 3 Apr 2022 11:34:48 +0000 Subject: [PATCH] cleanup: Use `static_assert` instead of `assert` where possible. This avoids some "always true condition" warnings and lifts the errors (if any) into compile time. --- other/bootstrap_daemon/docker/tox-bootstrapd.sha256 | 2 +- testing/BUILD.bazel | 1 - toxcore/Messenger.c | 2 +- toxcore/network.c | 6 ++++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index ce279f624..2540958cc 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -96618672392dc44a2f0a480f6415380e3fc588ace646345d31a297e80f7c271f /usr/local/bin/tox-bootstrapd +60f76a2186014870804b8dbacc16c68e8b019e02699584d007327a72de9e53de /usr/local/bin/tox-bootstrapd diff --git a/testing/BUILD.bazel b/testing/BUILD.bazel index b91e3cb95..68e89a159 100644 --- a/testing/BUILD.bazel +++ b/testing/BUILD.bazel @@ -18,7 +18,6 @@ sh_test( "-Wno-callgraph", "-Wno-enum-names", "-Wno-type-check", - "-Wno-var-unused-in-scope", "+RTS", "-N3", "-RTS", diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 28c8b0da2..d18f0a810 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -2744,7 +2744,7 @@ non_null() static uint8_t *save_nospam_keys(const Messenger *m, uint8_t *data) { const uint32_t len = m_plugin_size(m, STATE_TYPE_NOSPAMKEYS); - assert(sizeof(get_nospam(m->fr)) == sizeof(uint32_t)); + static_assert(sizeof(get_nospam(m->fr)) == sizeof(uint32_t), "nospam doesn't fit in a 32 bit int"); data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_NOSPAMKEYS); const uint32_t nospam = get_nospam(m->fr); host_to_lendian_bytes32(data, nospam); diff --git a/toxcore/network.c b/toxcore/network.c index 7d01382f9..6466a8a1d 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -313,13 +313,16 @@ static const Family *make_tox_family(int family) non_null() static void get_ip4(IP4 *result, const struct in_addr *addr) { + static_assert(sizeof(result->uint32) == sizeof(addr->s_addr), + "Tox and operating system don't agree on size of IPv4 addresses"); result->uint32 = addr->s_addr; } non_null() static void get_ip6(IP6 *result, const struct in6_addr *addr) { - assert(sizeof(result->uint8) == sizeof(addr->s6_addr)); + static_assert(sizeof(result->uint8) == sizeof(addr->s6_addr), + "Tox and operating system don't agree on size of IPv6 addresses"); memcpy(result->uint8, addr->s6_addr, sizeof(result->uint8)); } @@ -332,7 +335,6 @@ static void fill_addr4(const IP4 *ip, struct in_addr *addr) non_null() static void fill_addr6(const IP6 *ip, struct in6_addr *addr) { - assert(sizeof(ip->uint8) == sizeof(addr->s6_addr)); memcpy(addr->s6_addr, ip->uint8, sizeof(ip->uint8)); }