Use offsetof() instead of pointer arithmetics to get slabheader

In rdataset_getheader() a cast of the raw buffer to dns_slabheader_t and
pointer arithmetics was used to get the start of the slabheader
structure.  Use more correct offsetof(dns_slabheader_t, raw) to
calculate the correct start of the dns_slabheader_t from the flexible
member raw[].
This commit is contained in:
Ondřej Surý 2025-12-17 10:01:06 +01:00
parent 499cfc2f24
commit b8e07a0b5a
No known key found for this signature in database
GPG key ID: 2820F37E873DEA41

View file

@ -801,8 +801,8 @@ rdataset_getownercase(const dns_rdataset_t *rdataset, dns_name_t *name) {
static dns_slabheader_t *
rdataset_getheader(const dns_rdataset_t *rdataset) {
dns_slabheader_t *header = (dns_slabheader_t *)rdataset->slab.raw;
return header - 1;
uint8_t *rawbuf = rdataset->slab.raw;
return (dns_slabheader_t *)(rawbuf - offsetof(dns_slabheader_t, raw));
}
dns_slabtop_t *