Skip to content

Commit

Permalink
json.d: union pointer access is unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jul 19, 2016
1 parent 6cbaa94 commit 50d0023
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions std/json.d
Expand Up @@ -344,7 +344,8 @@ struct JSONValue
else static if (is(T : string))
{
type_tag = JSON_TYPE.STRING;
store.str = arg;
string t = arg;
() @trusted { store.str = t; }();
}
else static if (isSomeString!T) // issue 15884
{
Expand Down Expand Up @@ -380,29 +381,31 @@ struct JSONValue
type_tag = JSON_TYPE.OBJECT;
static if (is(Value : JSONValue))
{
store.object = arg;
JSONValue[string] t = arg;
() @trusted { store.object = t; }();
}
else
{
JSONValue[string] aa;
foreach (key, value; arg)
aa[key] = JSONValue(value);
store.object = aa;
() @trusted { store.object = aa; }();
}
}
else static if (isArray!T)
{
type_tag = JSON_TYPE.ARRAY;
static if (is(ElementEncodingType!T : JSONValue))
{
store.array = arg;
JSONValue[] t = arg;
() @trusted { store.array = t; }();
}
else
{
JSONValue[] new_arg = new JSONValue[arg.length];
foreach (i, e; arg)
new_arg[i] = JSONValue(e);
store.array = new_arg;
() @trusted { store.array = new_arg; }();
}
}
else static if (is(T : JSONValue))
Expand Down

0 comments on commit 50d0023

Please sign in to comment.