Skip to content

Commit c70e190

Browse files
hchunhuicdunn2001
authored andcommitted
Ensure Json::Value::null{,Ref} are initialized at compile time.
This bug was introduced in commit 48d9a92. gcc now puts Json::Value::null{,Ref} into bss section: $ nm libjsoncpp.a | c++filt | grep Value::null 0000000000000000 B Json::Value::null 0000000000000008 B Json::Value::nullRef When we access them in constructor of global objects, since the order of initialization is unpredictable, we may dereference a null pointer. After applying this patch, gcc puts them into rodata section: $ nm libjsoncpp.a | c++filt | grep Value::null 0000000000000008 R Json::Value::null 0000000000000010 R Json::Value::nullRef
1 parent f40dd0f commit c70e190

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/lib_json/json_value.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const Value Value::null;
3434
#define ALIGNAS(byte_alignment)
3535
#endif
3636
static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = { 0 };
37-
const unsigned char& kNullRef = kNull[0];
38-
const Value& Value::nullRef = reinterpret_cast<const Value&>(kNullRef);
37+
const Value& Value::null = reinterpret_cast<const Value&>(kNull[0]);
38+
const Value& Value::nullRef = reinterpret_cast<const Value&>(kNull[0]);
3939

4040
const Int Value::minInt = Int(~(UInt(-1) / 2));
4141
const Int Value::maxInt = Int(UInt(-1) / 2);

0 commit comments

Comments
 (0)