basic: add assert() when doing pointer deref
Lennart reminded me in [1] that we need to add assert() in functions that do pointer access. For the simple `*p` pointer dereferences we even have an automatic coccinelle script that ensures that as part of the automatic code checks. However for deref in the `p->` style this is not supported right now and adding it to coccinelle is hard because its too slow for this kind of check. So I created a (slightly messy) tree-sitter python script to see how many asserts we are currently missing. This commit is the result of running it over the `src/basic` dir and fixing the flagged issues. I plan to tidy it up and add it to the checks too but this is orthogonal to this commit. [1] https://github.com/systemd/systemd/pull/42360#discussion_r3426964562
This commit is contained in:
committed by
Lennart Poettering
parent
cd346b8ba7
commit
bc4dfc24a5
@@ -163,6 +163,8 @@ int in_addr_is_localhost_one(int family, const union in_addr_union *u) {
|
||||
}
|
||||
|
||||
bool in6_addr_is_ipv4_mapped_address(const struct in6_addr *a) {
|
||||
assert(a);
|
||||
|
||||
return a->s6_addr32[0] == 0 &&
|
||||
a->s6_addr32[1] == 0 &&
|
||||
a->s6_addr32[2] == htobe32(UINT32_C(0x0000ffff));
|
||||
@@ -728,6 +730,8 @@ int in4_addr_mask(struct in_addr *addr, unsigned char prefixlen) {
|
||||
int in6_addr_mask(struct in6_addr *addr, unsigned char prefixlen) {
|
||||
unsigned i;
|
||||
|
||||
assert(addr);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
uint8_t mask;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user