Skip to content

Commit 8050d8b

Browse files
committed
Merge pull request open-source-parsers#6 from cdunn2001/fix-static-init
I will try to pull the other changes from Chromium as well. This passed Travis.
2 parents 47f1577 + 28836b8 commit 8050d8b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

include/json/value.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class JSON_API Value {
133133
typedef Json::LargestUInt LargestUInt;
134134
typedef Json::ArrayIndex ArrayIndex;
135135

136-
static const Value null;
136+
static const Value& null;
137137
/// Minimum signed integer value that can be stored in a Json::Value.
138138
static const LargestInt minLargestInt;
139139
/// Maximum signed integer value that can be stored in a Json::Value.

src/lib_json/json_value.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,17 @@
2525

2626
namespace Json {
2727

28-
const Value Value::null;
28+
// This is a walkaround to avoid the static initialization of Value::null.
29+
// kNull must be word-aligned to avoid crashing on ARM. We use an alignment of
30+
// 8 (instead of 4) as a bit of future-proofing.
31+
#if defined(__ARMEL__)
32+
#define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
33+
#else
34+
#define ALIGNAS(byte_alignment)
35+
#endif
36+
static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = {0};
37+
const Value& Value::null = reinterpret_cast<const Value&>(kNull);
38+
2939
const Int Value::minInt = Int(~(UInt(-1) / 2));
3040
const Int Value::maxInt = Int(UInt(-1) / 2);
3141
const UInt Value::maxUInt = UInt(-1);

0 commit comments

Comments
 (0)