Skip to content

Commit

Permalink
cleanup: Use static_assert instead of assert where possible.
Browse files Browse the repository at this point in the history
This avoids some "always true condition" warnings and lifts the errors
(if any) into compile time.
  • Loading branch information
iphydf committed Apr 3, 2022
1 parent e49a477 commit 378febf
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
96618672392dc44a2f0a480f6415380e3fc588ace646345d31a297e80f7c271f /usr/local/bin/tox-bootstrapd
60f76a2186014870804b8dbacc16c68e8b019e02699584d007327a72de9e53de /usr/local/bin/tox-bootstrapd
1 change: 0 additions & 1 deletion testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ sh_test(
"-Wno-callgraph",
"-Wno-enum-names",
"-Wno-type-check",
"-Wno-var-unused-in-scope",
"+RTS",
"-N3",
"-RTS",
Expand Down
2 changes: 1 addition & 1 deletion toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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));
}

Expand Down

0 comments on commit 378febf

Please sign in to comment.