Skip to content
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

Seg Fault #411

Closed
xinthose opened this issue Aug 19, 2015 · 5 comments
Closed

Seg Fault #411

xinthose opened this issue Aug 19, 2015 · 5 comments

Comments

@xinthose
Copy link

Hello. I am getting a segmentation fault and do not know why. The C++ code is simply this:

std::string test = "{\"Val\":7}";           
document.Parse(test.c_str()).HasParseError()

I know it works elsewhere for me, so it could be in how I'm compiling and linking. This function is in a Boost thread and I also use Boost global logging. Thank you.

gdb output

----------------------------------------------------------------
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb659fb40 (LWP 3618)]
0x0806d697 in rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::GenericValue (this=0x10, s=0xb5a12600 "Val", length=3, allocator=...) at /usr/local/include/rapidjson/document.h:558
558     GenericValue(const Ch* s, SizeType length, Allocator& allocator) : data_(), flags_() { SetStringRaw(StringRef(s, length), allocator); }
------------------------------------
(gdb) list
553 
554     //! Constructor for constant string (i.e. do not make a copy of string)
555     explicit GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT : data_(), flags_() { SetStringRaw(s); }
556 
557     //! Constructor for copy-string (i.e. do make a copy of string)
558     GenericValue(const Ch* s, SizeType length, Allocator& allocator) : data_(), flags_() { SetStringRaw(StringRef(s, length), allocator); }
559 
560     //! Constructor for copy-string (i.e. do make a copy of string)
561     GenericValue(const Ch*s, Allocator& allocator) : data_(), flags_() { SetStringRaw(StringRef(s), allocator); }
562 
------------------------------------
(gdb) bt
#0  0x0806d697 in rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::GenericValue (this=0x10, s=0xb5a12600 "Val", length=3, allocator=...) at /usr/local/include/rapidjson/document.h:558
#1  0x0806cecf in rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>::String (this=0x80cab24 <_system_rapidjson+4>, str=0xb5a12600 "Val", length=3, copy=true)
    at /usr/local/include/rapidjson/document.h:2023
#2  0x0806ce21 in rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>::Key (this=0x80cab24 <_system_rapidjson+4>, str=0xb5a12600 "Val", length=3, copy=true)
    at /usr/local/include/rapidjson/document.h:2031
#3  0x0806b5b5 in rapidjson::GenericReader<rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::CrtAllocator>::ParseString<0u, rapidjson::GenericStringStream<rapidjson::UTF8<char> >, rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator> > (this=0xb659ee8c, is=..., handler=..., isKey=true)
    at /usr/local/include/rapidjson/reader.h:657
#4  0x0806b874 in rapidjson::GenericReader<rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::CrtAllocator>::ParseObject<0u, rapidjson::GenericStringStream<rapidjson::UTF8<char> >, rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator> > (this=0xb659ee8c, is=..., handler=...)
    at /usr/local/include/rapidjson/reader.h:487
#5  0x0806a8ec in rapidjson::GenericReader<rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::CrtAllocator>::ParseValue<0u, rapidjson::GenericStringStream<rapidjson::UTF8<char> >, rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator> > (this=0xb659ee8c, is=..., handler=...)
    at /usr/local/include/rapidjson/reader.h:993
#6  0x0806a2ab in rapidjson::GenericReader<rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::CrtAllocator>::Parse<0u, rapidjson::GenericStringStream<rapidjson::UTF8<char> >, rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator> > (this=0xb659ee8c, is=..., handler=...)
    at /usr/local/include/rapidjson/reader.h:408
#7  0x08069c95 in rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>::ParseStream<0u, rapidjson::UTF8<char>, rapidjson::GenericStringStream<rapidjson::UTF8<char> > > (
    this=0x80cab24 <_system_rapidjson+4>, is=...) at /usr/local/include/rapidjson/document.h:1892
#8  0x08069593 in rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>::Parse<0u, rapidjson::UTF8<char> > (this=0x80cab24 <_system_rapidjson+4>, 
    str=0xb5a13054 "{\"Val\":7}") at /usr/local/include/rapidjson/document.h:1957
#9  0x08068e9a in rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>::Parse<0u> (this=0x80cab24 <_system_rapidjson+4>, str=0xb5a13054 "{\"Val\":7}")
    at /usr/local/include/rapidjson/document.h:1966
#10 0x080687a6 in rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>::Parse (this=0x80cab24 <_system_rapidjson+4>, str=0xb5a13054 "{\"Val\":7}")
    at /usr/local/include/rapidjson/document.h:1973
#11 0x080679c1 in system_rapidjson::read_json_str (this=0x80cab20 <_system_rapidjson>, 
    json_str="{\"Description\":\"DATABASE TASK MODE VALUE\",\"Name\":\"TASK\",\"Val\":0,\"addID\":0,\"CreatedAt\":\"2015-08-12T17:57:03.954Z\",\"ModifiedAt\":\"2015-08-19T21:26:02.354Z\",\"CreatedBy\":\"00000000-0000-0000-0000-0000000000"...)
    at src/rapidjson.cpp:64
#12 0x0808b041 in check_task () at src/main.cpp:68
#13 0x08095dc3 in boost::detail::thread_data<void (*)()>::run (this=0x80f8728)
---Type <return> to continue, or q <return> to quit---
    at /usr/include/boost/thread/detail/thread.hpp:117
#14 0xb7fb1f16 in ?? () from /usr/lib/i386-linux-gnu/libboost_thread.so.1.55.0
#15 0xb7d03d97 in start_thread (arg=0xb659fb40) at pthread_create.c:309
#16 0xb76d2dfe in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:129
@xinthose
Copy link
Author

I already gave up. string.find () works just as well. I just want to extract "Val" 's from JSON

@miloyip
Copy link
Collaborator

miloyip commented Aug 21, 2015

I cannot diagnose the problem from the information.
Will it be possible that your program using more than one version of RapidJSON?

@ImmortalDragonm
Copy link

Is RapidJSON thread safe?

@xinthose
Copy link
Author

I am having weird problems in my code elsewhere. I wasn't sure if the gdb output could help at all. I only installed it once. I found boost property tree works well for me in a threaded environment: http://tiny.cc/25eb2x ; Thank you.

@miloyip
Copy link
Collaborator

miloyip commented Aug 22, 2015

@ImmortalDragonm
RapidJSON is not thread-safe per se. But different instances of RapidJSON objects does not interfere each other. No global/static-member variable is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants