这是导致崩溃的行:
if (size <= 0)
return;
if (data)
{
std::string sData = std::string((char*)data, size);
buffer += sData; <-- This is the line causing crash
processBuffer();
}
else
return;
这是堆栈跟踪:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1282016352 (LWP 27952)]
0x002b48ec in memcpy () from /lib/tls/libc.so.6
(gdb) bt
#0 0x002b48ec in memcpy () from /lib/tls/libc.so.6
#1 0x001fea31 in std::string::_Rep::_M_clone () from /usr/lib/libstdc++.so.6
#2 0x001fef2e in std::string::reserve () from /usr/lib/libstdc++.so.6
#3 0x001ff83d in std::string::append () from /usr/lib/libstdc++.so.6
#4 0x001ff9e2 in std::string::operator+= () from /usr/lib/libstdc++.so.6
#5 0x003fc6c8 in StreamDecoder::StreamDecoderEncoder::addData
at src/StreamDecoder.cpp:171
我已经验证data
不为空,缓冲区是声明为该类的私有成员变量的字符串。
我不知道为什么memcpy会出现段错误。这里可能出了什么问题?