-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Json::Value::null is constructed at random time during program initialization, and can cause segfault #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
On Wednesday, June 22, 2016, Mark Lakata notifications@github.com wrote:
If you have access to "magic statics" (msft term) you can just new a Value const Value& Value::nullref() { Or something similar.
ǝnɥɐuop ʎllıq |
I updated my proposal with a better implementation. I think the existing code with the |
The But that change had to be reverted (93f45d0) because it broke binary-compatibility. I would never have included a global without a way to initialize, but that's a long time ago. Note that initialization is safe in an Although we absolutely cannot remove these symbols, we can use a wrapper in our code, as @marklakata suggests. That should work for the vast majority of cases, and as @BillyGoto points out, nobody should be using it anyway. Hi, Mark. We currently use
We use I don't think any of those are used by ctors, but that's not really the point. We don't need to refer to it directly. I'll submit a PR with your code... |
Avoid some static initialization problems. From @marklakata See #488
Avoid some static initialization problems. From @marklakata See #488
The
Json::Value::null
object is a global reference object. The rules of C++ allow other constructors from other translation units to access theJson::Value::null
symbol before it is constructed, which means that the reference is bogus, and you get a segmentation violation for accessing it. That means if you have a global object that usesJson::Value
in its constructor, it can easily crash, depending on the whim of the linker deciding what to link first.The solution (which I have shown works in my private workspace) is to replace all instances of
Json::Value::null
with static function (sayJson::Value::null_()
) in the style of a Meyers Singleton. Then accesses tonull_()
will always be valid and not depend on a race condition of the global construction list.and replaced all the references to
null
in the JSONCPP code tonull_()
. This works now and I can use Json::Value in a constructor of a global object without it crashing.The text was updated successfully, but these errors were encountered: