-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
GetInt coredump #729
Comments
不能重现: #include "rapidjson/document.h"
#include <cstdio>
using namespace rapidjson;
int main() {
const char json[] = "{\"errmsg\":\"Transportendpointisnotconnected\",\"results\":[null],\"retcode\":-1}";
Document root;
root.Parse(json);
if (root["retcode"] != 0) {
printf("curl retcode=%d errmsg=%s\n", root["retcode"].GetInt(), root["errmsg"].GetString());
}
}
|
我自己也被迷惑了,不知道是不是其他的原因导致的;目前从coredump看到的情况是这样的。gdb 结果 |
|
root是一个局部变量,函数调用时申请的,非指针不存在提前释放。 |
你试试 valgrind 跑一下,看看有没有非法的内存访问? |
嗯,正准备搞一搞试试 |
有进展么? |
我也遇到同样的问题,当rapidjson和libcurl同时使用时会随机coredump,目前还在找原因,不知道有没有最新进展? |
这是我的代码(原谅没有试用FindMember来获取,偷懒测试)
if(root.Parse(result.c_str()).HasParseError())
{
WRN("parse json got err %d.\n",root.GetParseError());
return -1;
}
if (root[“retcode”]!= 0) { //core 在这一行,
WRN("curl retcode=%d errmsg=%s\n", root[“retcode”], root["errmsg"].GetString());
return -1;
}
gdb 显示的结果:#0 0x000000000041cfb6 in rapidjson::GenericValuerapidjson::UTF8<char, rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator >::GetInt (
this=0x10) at rapidjson/document.h:1645 //这里段错误
照源码来看,无论如何也不应该是段错误,如果json里面没有‘retcode’或者‘retcode’类型不是int,都应该在RAPIDJSON_ASSERT上core(实际上json是有这个字段的,并且类型也是int)。
这里到底是什么原因导致的呢?请教
附:json
{
"errmsg": "Transportendpointisnotconnected",
"results": [
null
],
"retcode": -1
}
The text was updated successfully, but these errors were encountered: