From: Francis Ma Date: Mon, 6 Oct 2014 23:34:06 +0000 (-0700) Subject: Move static member inside the scope of the function X-Git-Tag: v0.22.0~297 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=e401a93c31c351a48a21dae97fcd7c3b07d7790c;p=folly.git Move static member inside the scope of the function Summary: We are seeing crashes which comes from the initialization of the static global variable. This particular variable is used only in a single function that was never invoked. So moving it into the scope of the function will at least solve the problem. The real issue still requires some deep investigation though. Test Plan: unitest under folly passed Reviewed By: subodh@fb.com Subscribers: seanc, njormrod FB internal diff: D1598048 Tasks: 5316441 --- diff --git a/folly/IPAddressV4.cpp b/folly/IPAddressV4.cpp index a5db28fc..d66993c4 100644 --- a/folly/IPAddressV4.cpp +++ b/folly/IPAddressV4.cpp @@ -28,7 +28,6 @@ using std::string; namespace folly { -static IPAddressV4 loopback_addr("127.0.0.0"); // free functions size_t hash_value(const IPAddressV4& addr) { @@ -146,6 +145,7 @@ bool IPAddressV4::inSubnetWithMask(const IPAddressV4& subnet, } bool IPAddressV4::isLoopback() const { + static IPAddressV4 loopback_addr("127.0.0.0"); return inSubnetWithMask(loopback_addr, fetchMask(8)); } diff --git a/folly/IPAddressV4.h b/folly/IPAddressV4.h index ac63ef8f..9c66afb6 100644 --- a/folly/IPAddressV4.h +++ b/folly/IPAddressV4.h @@ -226,6 +226,8 @@ class IPAddressV4 : boost::totally_ordered { private: union AddressStorage { + static_assert(sizeof(in_addr) == sizeof(ByteArray4), + "size of in_addr and ByteArray4 are different"); in_addr inAddr_; ByteArray4 bytes_; AddressStorage() {