Boost logo

Boost :

Subject: Re: [boost] [property_tree] Issue: erase is corrupting the tree
From: lukas.exler_at_[hidden]
Date: 2017-06-06 08:32:17


The minimal code that crashes is:
    boost::property_tree::ptree loadedJSON;
    boost::property_tree::read_json("animalList.json", loadedJSON);
    auto assoc_it = loadedJSON.find("animals");
    auto it = loadedJSON.to_iterator(assoc_it);
    it = it->second.begin();
    it++; // move to second item
    loadedJSON.erase(it);
    boost::property_tree::write_json("shorterList.json", loadedJSON);

Where content of "animalList.json" file is:
{
    "animals" : ["fox","dog","cat"]
}


-----Original Message-----
From: Mert Büyüktuncay [mailto:mert.buyuktuncay_at_[hidden]]
Sent: Tuesday, June 06, 2017 9:22 AM
To: boost_at_[hidden]
Cc: Exler, Lukas: IT (PRG)
Subject: RE: [property_tree] Issue: erase is corrupting the tree

This mail originated from outside our organisation

Do you use "it" iterator after the call to erase in that case you shall use it = loadedJSON.erase(it); instead of
it++
If this is not your problem you can share a little more code for us to see in detail what is happening here. May be the code up to the point where "write_json" is being called.

Regards
Mert

-----Original Message-----
From: Boost [mailto:boost-bounces_at_[hidden]] On Behalf Of Lukas via Boost
Sent: Monday, June 5, 2017 4:08 PM
To: boost_at_[hidden]
Cc: lukas.exler_at_[hidden]
Subject: [boost] [property_tree] Issue: erase is corrupting the tree

I have following JSON structure loaded into boost::property_tree:
{
    "animals" : ["fox","dog","cat"]
}

I'm trying to delete the second item from the array by:
        auto assoc_it = loadedJSON.find("animals");
        auto it = loadedJSON.to_iterator(assoc_it);
        it = it->second.begin();
        it++; // move to second item
        loadedJSON.erase(it);

After this, when I try to use boost::property_tree::write_json to write the JSON back the app crashes. Do I use the property tree in a wrong way, or is there a bug?

Thanks,
Lukas.

_______________________________________________

This message is for information purposes only, it is not a recommendation, advice, offer or solicitation to buy or sell a product or service nor an official confirmation of any transaction. It is directed at persons who are professionals and is not intended for retail customer use. Intended for recipient only. This message is subject to the terms at: www.barclays.com/emaildisclaimer.

For important disclosures, please see: www.barclays.com/salesandtradingdisclaimer regarding market commentary from Barclays Sales and/or Trading, who are active market participants; and in respect of Barclays Research, including disclosures relating to specific issuers, please see http://publicresearch.barclays.com.

_______________________________________________

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Bu elektronik posta mesajı ve ekleri sadece gönderildiği kişi veya kuruma özeldir ve gizli bilgiler içerebilir. Eğer bu mesajı hataen aldıysanız lütfen bu durumu gönderen kişiye derhal bildiriniz ve mesajı sisteminizden siliniz. Eğer doğru kişiye ulaşmadığını düşünüyorsanız, bu mesajın gizlenmesi, yönlendirilmesi, kopyalanması veya herhangi bir şekilde kullanılması yasaktır. Internet iletişiminde güvenlik ve hatasız gönderim garanti edilemeyeceğinden, mesajın yerine ulaşmaması, geç ulaşması, içeriğinin bozulması ya da mesajın virüs taşıması gibi problemler oluşabilir. Gönderen taraf bu tip sorunlardan sorumlu tutulmaz.
SESTEK Ses ve Ä°letiÅŸim Teknolojileri A.Åž.
www.sestek.com<http://www.sestek.com>

This e-mail message and any attachments are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this message in error, please notify the sender immediately and delete it from your system. If you are not the intended recipient you are hereby notified that any dissemination, forwarding, copying or use of any of the information is prohibited. Internet communications cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, arrive late or contain viruses. The sender therefore does not accept liability for any errors or omissions in the context of this message which arise as a result of Internet transmission SESTEK INC.
www.sestek.com <http://www.sestek.com>
Bu elektronik posta mesajı ve ekleri sadece gönderildiği kişi veya kuruma özeldir ve gizli bilgiler içerebilir. Eğer bu mesajı hataen aldıysanız lütfen bu durumu gönderen kişiye derhal bildiriniz ve mesajı sisteminizden siliniz. Eğer doğru kişiye ulaşmadığını düşünüyorsanız, bu mesajın gizlenmesi, yönlendirilmesi, kopyalanması veya herhangi bir şekilde kullanılması yasaktır. Internet iletişiminde güvenlik ve hatasız gönderim garanti edilemeyeceğinden, mesajın yerine ulaşmaması, geç ulaşması, içeriğinin bozulması ya da mesajın virüs taşıması gibi problemler oluşabilir. Gönderen taraf bu tip sorunlardan sorumlu tutulmaz.
SESTEK Ses ve Ä°letiÅŸim Teknolojileri A.Åž.
www.sestek.com<http://www.sestek.com>

This e-mail message and any attachments are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this message in error, please notify the sender immediately and delete it from your system. If you are not the intended recipient you are hereby notified that any dissemination, forwarding, copying or use of any of the information is prohibited. Internet communications cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, arrive late or contain viruses. The sender therefore does not accept liability for any errors or omissions in the context of this message which arise as a result of Internet transmission SESTEK INC.
www.sestek.com <http://www.sestek.com>

_______________________________________________

This message is for information purposes only, it is not a recommendation, advice, offer or solicitation to buy or sell a product or service nor an official confirmation of any transaction. It is directed at persons who are professionals and is not intended for retail customer use. Intended for recipient only. This message is subject to the terms at: www.barclays.com/emaildisclaimer.

For important disclosures, please see: www.barclays.com/salesandtradingdisclaimer regarding market commentary from Barclays Sales and/or Trading, who are active market participants; and in respect of Barclays Research, including disclosures relating to specific issuers, please see http://publicresearch.barclays.com.

_______________________________________________


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk