Jsoncpp库的一个bug
发布时间:2020-12-16 19:07:13 所属栏目:百科 来源:网络整理
导读:Jsoncpp有个bug 定义全局对象Value并赋值,类似下面这样,在程序退出的时候会崩溃。 Value s_test;int WINAPI WinMain(HINSTANCE s,HINSTANCE p,char * cmd,int show){ s_test["aaa"] = 1;} 原因是这里,在全局变量析构之前,这个静态变量已经析构了。 stati
Jsoncpp有个bug
定义全局对象Value并赋值,类似下面这样,在程序退出的时候会崩溃。 Value s_test; int WINAPI WinMain(HINSTANCE s,HINSTANCE p,char * cmd,int show) { s_test["aaa"] = 1; } 原因是这里,在全局变量析构之前,这个静态变量已经析构了。 static ValueAllocator *&valueAllocator() { static DefaultValueAllocator defaultAllocator; static ValueAllocator *valueAllocator = &defaultAllocator; return valueAllocator; } 改成这样就ok了。 static ValueAllocator *&valueAllocator() { static DefaultValueAllocator *defaultAllocator = NULL; if (defaultAllocator == NULL) { defaultAllocator = new DefaultValueAllocator; } static ValueAllocator *valueAllocator = defaultAllocator; return valueAllocator; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |