memset struct padding

This commit is contained in:
ruti 2024-09-18 15:29:53 +03:00
parent a9ecc83932
commit 889391b7b1

View File

@ -49,24 +49,21 @@ int mode_add_get(struct sockaddr_ina *dst, int m)
{ {
// m < 0: get, m > 0: set, m == 0: delete // m < 0: get, m > 0: set, m == 0: delete
assert(m >= -1 && m < params.dp_count); assert(m >= -1 && m < params.dp_count);
#pragma pack(push,4)
struct key_struct { struct key_struct {
uint16_t port; uint16_t port;
uint16_t pad0; // fill with 0 before use!
union { union {
struct in_addr i4; struct in_addr i4;
struct in6_addr i6; struct in6_addr i6;
}; };
} key = { .port = dst->in.sin_port, .pad0 = 0 }; } key = { 0 };
#pragma pack(pop)
#if defined(__GNUC__) int len = offsetof(struct key_struct, i4);
_Static_assert(offsetof(struct key_struct, i4) == sizeof(key.port)+sizeof(key.pad0), "key_struct"); memset(&key, 0, len);
#endif key.port = dst->in.sin_port;
time_t t = 0; time_t t = 0;
struct elem *val = 0; struct elem *val = 0;
int len = offsetof(struct key_struct, i4);
if (dst->sa.sa_family == AF_INET) { if (dst->sa.sa_family == AF_INET) {
len += sizeof(dst->in.sin_addr); len += sizeof(dst->in.sin_addr);
key.i4 = dst->in.sin_addr; key.i4 = dst->in.sin_addr;