Skip to content

Commit

Permalink
cleanup: Remove any disallowed casts.
Browse files Browse the repository at this point in the history
The ones in toxav weren't needed. The ones in network.c are
non-trivially correct. Now, the code is more easily verifiable.
  • Loading branch information
iphydf committed Feb 22, 2022
1 parent 2760966 commit 9a5e628
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 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 @@
e60be1422bb4ba3bf080faca429174afb4804211d5d5fe1ba365ed65f505b361 /usr/local/bin/tox-bootstrapd
8ae148d2a77c9e9c2be54dc25c8c22b81d812ea3a20b0e0503fb92659f1f3e65 /usr/local/bin/tox-bootstrapd
2 changes: 1 addition & 1 deletion testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sh_test(
name = "cimplefmt_test",
size = "small",
srcs = ["//hs-cimple/tools:cimplefmt"],
args = ["$(locations %s)" % f for f in CIMPLE_FILES],
args = ["--reparse"] + ["$(locations %s)" % f for f in CIMPLE_FILES],
data = CIMPLE_FILES,
tags = ["haskell"],
)
Expand Down
2 changes: 1 addition & 1 deletion toxav/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ void vc_iterate(VCSession *vc)
dest = vpx_codec_get_frame(vc->decoder, &iter)) {
if (vc->vcb != nullptr) {
vc->vcb(vc->av, vc->friend_number, dest->d_w, dest->d_h,
(const uint8_t *)dest->planes[0], (const uint8_t *)dest->planes[1], (const uint8_t *)dest->planes[2],
dest->planes[0], dest->planes[1], dest->planes[2],
dest->stride[0], dest->stride[1], dest->stride[2], vc->vcb_user_data);
}

Expand Down
8 changes: 6 additions & 2 deletions toxcore/ccompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@
#if !defined(__cplusplus) || __cplusplus < 201103L
#define nullptr NULL
#ifndef static_assert
#ifdef __GNUC__
#define static_assert(cond, msg) extern __attribute__((__unused__)) const int unused_for_static_assert
#else // !__GNUC__
#define static_assert(cond, msg) extern const int unused_for_static_assert
#endif
#endif
#endif // !__GNUC__
#endif // !static_assert
#endif // !__cplusplus

#ifdef __GNUC__
#define GNU_PRINTF(f, a) __attribute__((__format__(__printf__, f, a)))
Expand Down
12 changes: 8 additions & 4 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,15 +1273,19 @@ bool ip_parse_addr(const IP *ip, char *address, size_t length)
}

if (net_family_is_ipv4(ip->family)) {
const struct in_addr *addr = (const struct in_addr *)&ip->ip.v4;
struct in_addr addr;
addr.s_addr = ip->ip.v4.uint32;
assert(make_family(ip->family) == AF_INET);
return inet_ntop4(addr, address, length) != nullptr;
return inet_ntop4(&addr, address, length) != nullptr;
}

if (net_family_is_ipv6(ip->family)) {
const struct in6_addr *addr = (const struct in6_addr *)&ip->ip.v6;
struct in6_addr addr;
static_assert(sizeof(addr.s6_addr) == sizeof(ip->ip.v6.uint8),
"assumption does not hold: s6_addr should be 16 bytes");
memcpy(addr.s6_addr, ip->ip.v6.uint8, sizeof(ip->ip.v6.uint8));
assert(make_family(ip->family) == AF_INET6);
return inet_ntop6(addr, address, length) != nullptr;
return inet_ntop6(&addr, address, length) != nullptr;
}

return false;
Expand Down

0 comments on commit 9a5e628

Please sign in to comment.