Commit 61c3151a authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Avoid explicit memset in IPAddress storage union

Summary: [Folly] Avoid explicit `memset` in `IPAddress` storage union by having an explicit storage field and value-initializing it in the default constructor.

Reviewed By: stevegury

Differential Revision: D14270246

fbshipit-source-id: f1f135f20709d8225e984ee3d6b397d4b04e0d76
parent a0e3a745
...@@ -442,12 +442,11 @@ class IPAddress { ...@@ -442,12 +442,11 @@ class IPAddress {
[[noreturn]] void asV6Throw() const; [[noreturn]] void asV6Throw() const;
typedef union IPAddressV46 { typedef union IPAddressV46 {
std::aligned_union_t<0, IPAddressV4, IPAddressV6> storage;
IPAddressV4 ipV4Addr; IPAddressV4 ipV4Addr;
IPAddressV6 ipV6Addr; IPAddressV6 ipV6Addr;
// default constructor // default constructor
IPAddressV46() noexcept { IPAddressV46() noexcept : storage() {}
std::memset(this, 0, sizeof(IPAddressV46));
}
explicit IPAddressV46(const IPAddressV4& addr) noexcept : ipV4Addr(addr) {} explicit IPAddressV46(const IPAddressV4& addr) noexcept : ipV4Addr(addr) {}
explicit IPAddressV46(const IPAddressV6& addr) noexcept : ipV6Addr(addr) {} explicit IPAddressV46(const IPAddressV6& addr) noexcept : ipV6Addr(addr) {}
} IPAddressV46; } IPAddressV46;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment