std.json segmentation fault

Maxim Fomin maxim at maxim-fomin.ru
Mon Feb 4 14:10:40 PST 2013


On Monday, 4 February 2013 at 21:16:51 UTC, Vladimir Panteleev 
wrote:
> On Monday, 4 February 2013 at 10:04:10 UTC, Andrea Fontana 
> wrote:
>> This code was working some months ago:
>>
>> import std.json;
>> JSONValue total;
>> total.type = JSON_TYPE.OBJECT;
>> total["results"].type = JSON_TYPE.OBJECT;
>>
>>
>> Now, last line gives me a segmentation fault. What's wrong 
>> with this code?
>
> https://github.com/D-Programming-Language/phobos/pull/561/files
>
> Is this code right? Has it ever worked?

I think it depends on how std.json is defined. It is up to 
implementator to define whether such things should be supported 
or not.

> I don't think returning a ref value of an AA works for adding 
> items to an AA.

He doesn't add item to AA. The code just queries a reference to 
item from array and since opIndex returns null, any attempt to 
construct a stack variable from null reference leads to segfault. 
By no means the code can manipulate AA using returned struct 
since it is copied, even if opIndex returns by reference.

> That pull request didn't come with any unit tests... shouldn't 
> have made it through review, IMO.




More information about the Digitalmars-d mailing list