mirror of
https://github.com/TokTok/c-toxcore
synced 2026-10-23 08:42:21 +00:00
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.
This commit is contained in:
4 files changed
+6
-5
No files matched your search
@@ -1 +1 @@
|
||||
96618672392dc44a2f0a480f6415380e3fc588ace646345d31a297e80f7c271f /usr/local/bin/tox-bootstrapd
|
||||
60f76a2186014870804b8dbacc16c68e8b019e02699584d007327a72de9e53de /usr/local/bin/tox-bootstrapd
|
||||
@@ -18,7 +18,6 @@ sh_test(
|
||||
"-Wno-callgraph",
|
||||
"-Wno-enum-names",
|
||||
"-Wno-type-check",
|
||||
"-Wno-var-unused-in-scope",
|
||||
"+RTS",
|
||||
"-N3",
|
||||
"-RTS",
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+4
-2
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user