Move static member inside the scope of the function
authorFrancis Ma <fma@fb.com>
Mon, 6 Oct 2014 23:34:06 +0000 (16:34 -0700)
committerAndrii Grynenko <andrii@fb.com>
Wed, 15 Oct 2014 00:55:18 +0000 (17:55 -0700)
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

folly/IPAddressV4.cpp
folly/IPAddressV4.h

index a5db28fc50933d52375985b2ba5df1b0a69069de..d66993c4bde13d359e205881ac3f71e08a44e195 100644 (file)
@@ -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));
 }
 
index ac63ef8f98f36e45d83979c26a1255a887f1e97d..9c66afb64f18d522c69e09456cf2e45145cab3ec 100644 (file)
@@ -226,6 +226,8 @@ class IPAddressV4 : boost::totally_ordered<IPAddressV4> {
 
  private:
   union AddressStorage {
+    static_assert(sizeof(in_addr) == sizeof(ByteArray4),
+                  "size of in_addr and ByteArray4 are different");
     in_addr inAddr_;
     ByteArray4 bytes_;
     AddressStorage() {