The `dnsheader_aligned` object contains a pointer that references
either the `dnsheader` passed to the constructor if it is properly
aligned, or the internal `dnsheader` member. In the second case,
making a copy would mean we can reference an object that has been
destructed, which is a serious problem.
This commit also ensures copy elision is done `DNSQuestion:getHeader`,
as otherwise the compiler might refuse to compile.
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
d_p = &d_h;
}
}
+ dnsheader_aligned(const dnsheader_aligned&) = delete;
+ dnsheader_aligned(dnsheader_aligned&&) = delete;
+ dnsheader_aligned& operator=(const dnsheader_aligned&) = delete;
+ dnsheader_aligned& operator=(dnsheader_aligned&&) = delete;
+ ~dnsheader_aligned() = default;
[[nodiscard]] const dnsheader* get() const
{
if (data.size() < sizeof(dnsheader)) {
throw std::runtime_error("Trying to access the dnsheader of a too small (" + std::to_string(data.size()) + ") DNSQuestion buffer");
}
- dnsheader_aligned dh(data.data());
- return dh;
+ return dnsheader_aligned(data.data());
}
/* this function is not safe against unaligned access, you should