{"action":"created","issue":{"url":"https://api.github.com/repos/miloyip/rapidjson/issues/301","labels_url":"https://api.github.com/repos/miloyip/rapidjson/issues/301/labels{/name}","comments_url":"https://api.github.com/repos/miloyip/rapidjson/issues/301/comments","events_url":"https://api.github.com/repos/miloyip/rapidjson/issues/301/events","html_url":"https://github.com/miloyip/rapidjson/issues/301","id":68291104,"number":301,"title":"Crash when passing nearly-empty document","user":{"login":"RSpliet","id":437268,"avatar_url":"https://avatars.githubusercontent.com/u/437268?v=3","gravatar_id":"","url":"https://api.github.com/users/RSpliet","html_url":"https://github.com/RSpliet","followers_url":"https://api.github.com/users/RSpliet/followers","following_url":"https://api.github.com/users/RSpliet/following{/other_user}","gists_url":"https://api.github.com/users/RSpliet/gists{/gist_id}","starred_url":"https://api.github.com/users/RSpliet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RSpliet/subscriptions","organizations_url":"https://api.github.com/users/RSpliet/orgs","repos_url":"https://api.github.com/users/RSpliet/repos","events_url":"https://api.github.com/users/RSpliet/events{/privacy}","received_events_url":"https://api.github.com/users/RSpliet/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/miloyip/rapidjson/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/miloyip/rapidjson/milestones/2","html_url":"https://github.com/miloyip/rapidjson/milestones/v1.0%20RC","labels_url":"https://api.github.com/repos/miloyip/rapidjson/milestones/2/labels","id":1061883,"number":2,"title":"v1.0 RC","description":"v1.0 release candidate","creator":{"login":"miloyip","id":1195774,"avatar_url":"https://avatars.githubusercontent.com/u/1195774?v=3","gravatar_id":"","url":"https://api.github.com/users/miloyip","html_url":"https://github.com/miloyip","followers_url":"https://api.github.com/users/miloyip/followers","following_url":"https://api.github.com/users/miloyip/following{/other_user}","gists_url":"https://api.github.com/users/miloyip/gists{/gist_id}","starred_url":"https://api.github.com/users/miloyip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miloyip/subscriptions","organizations_url":"https://api.github.com/users/miloyip/orgs","repos_url":"https://api.github.com/users/miloyip/repos","events_url":"https://api.github.com/users/miloyip/events{/privacy}","received_events_url":"https://api.github.com/users/miloyip/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":5,"state":"open","created_at":"2015-04-10T12:46:21Z","updated_at":"2015-04-15T15:59:30Z","due_on":"2015-04-16T16:00:00Z","closed_at":null},"comments":13,"created_at":"2015-04-14T07:28:54Z","updated_at":"2015-04-17T08:35:32Z","closed_at":null,"body":"RapidJSON (debian, 0.12~git20141031-1) seems to crash when I pass it as a string the simple document \"{ }\". Expected is either a graceful failure in `hasParseError()` or a `return false` on subsequent `hasMember()` requests. Instead, the following occurs:\r\n~~~\r\nProgram received signal SIGSEGV, Segmentation fault.\r\n1551\t        data_.o.members = (Member*)allocator.Malloc(count * sizeof(Member));\r\n(gdb) bt\r\n#0  SetObjectRaw (allocator=..., count=0, members=0x1edc20, this=0x1edc08) at /usr/include/rapidjson/document.h:1551\r\n#1  EndObject (memberCount=0, this=<optimized out>) at /usr/include/rapidjson/document.h:1852\r\n#2  rapidjson::GenericReader<rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::ParseObject<0u, rapidjson::GenericStringStream<rapidjson::UTF8<char> >, rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator> > (this=<optimized out>, is=..., \r\n    handler=...) at /usr/include/rapidjson/reader.h:467\r\n#3  0x00034662 in Parse<0u, rapidjson::GenericStringStream<rapidjson::UTF8<> >, rapidjson::GenericDocument<rapidjson::UTF8<> > > (handler=..., is=..., this=0xbefff4c8)\r\n    at /usr/include/rapidjson/reader.h:397\r\n#4  ParseStream<0u, rapidjson::UTF8<>, rapidjson::GenericStringStream<rapidjson::UTF8<> > > (is=..., this=0xbefff500) at /usr/include/rapidjson/document.h:1698\r\n#5  Parse<0u, rapidjson::UTF8<> > (str=<optimized out>, this=0xbefff500) at /usr/include/rapidjson/document.h:1774\r\n#6  Parse<0u> (str=<optimized out>, this=0xbefff500) at /usr/include/rapidjson/document.h:1783\r\n#7  Parse (str=<optimized out>, this=0xbefff500) at /usr/include/rapidjson/document.h:1790\r\n#8  Settings::fillByJSON (this=this@entry=0x1edbc0, json=\"{ }\") at /Embedded/src/Util/Settings.cpp:75\r\n#9  0x0003dd96 in ArcusView::doSettings (this=this@entry=0x97b80, msg=msg@entry=0xb3b00518) at /Embedded/src/View/ArcusView.cpp:56\r\n#10 0x0002c17a in ArcusView::main (this=this@entry=0x97b80) at /Embedded/src/View/ArcusView.cpp:364\r\n#11 0x0002c8a6 in main (argc=<optimized out>, argv=<optimized out>) at /Embedded/src/main.cpp:35\r\n~~~\r\nAlthough I hardly know the code, I suspect this might have something to do with `malloc()` being called with size 0. But I'll leave that bit to the experts!\r\nCould you look into this please?"},"comment":{"url":"https://api.github.com/repos/miloyip/rapidjson/issues/comments/93943705","html_url":"https://github.com/miloyip/rapidjson/issues/301#issuecomment-93943705","issue_url":"https://api.github.com/repos/miloyip/rapidjson/issues/301","id":93943705,"user":{"login":"RSpliet","id":437268,"avatar_url":"https://avatars.githubusercontent.com/u/437268?v=3","gravatar_id":"","url":"https://api.github.com/users/RSpliet","html_url":"https://github.com/RSpliet","followers_url":"https://api.github.com/users/RSpliet/followers","following_url":"https://api.github.com/users/RSpliet/following{/other_user}","gists_url":"https://api.github.com/users/RSpliet/gists{/gist_id}","starred_url":"https://api.github.com/users/RSpliet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RSpliet/subscriptions","organizations_url":"https://api.github.com/users/RSpliet/orgs","repos_url":"https://api.github.com/users/RSpliet/repos","events_url":"https://api.github.com/users/RSpliet/events{/privacy}","received_events_url":"https://api.github.com/users/RSpliet/received_events","type":"User","site_admin":false},"created_at":"2015-04-17T08:35:32Z","updated_at":"2015-04-17T08:35:32Z","body":"Alignment to 4-bytes should be sufficient on ARMv7; the architecture does not specify stricter alignment requirements. Using CrtAllocator does solve the issues, pointing in the direction of the MemoryPoolAllocator.\r\nI suggest to use CrtAllocator by default on ARM for both GenericDocument and GenericValue. Furthermore, and this is not to sound condescending but rather to be helpful, I would be interested to learn what the performance impact of such a move on other platforms would have. My experience is that the default memory allocator on at least Linux is already using memory pools to avoid kernel roundtrips for every allocation in addition to not using the expensive and exhaustive mmap method for smaller allocations. With [this paper](http://dl.acm.org/citation.cfm?id=2502522&dl=ACM&coll=DL&CFID=664459021&CFTOKEN=82607958) in mind, benchmarks could give incentive to simplify the current code-base as opposed to spending a lot of time trying to make the MemoryPoolAllocator suitable for ARM.\r\n\r\nEither way, I hope this feedback is sufficient to help you get rapidjson running on ARM! Thanks for your time and effort to help me debug."}}