Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 程序崩溃,程序接收信号EXC_坏访问,无法访问内存。原因:地址0x00000000处的内核保护失败_C++_Pthreads_Exc Bad Access - Fatal编程技术网

C++ 程序崩溃,程序接收信号EXC_坏访问,无法访问内存。原因:地址0x00000000处的内核保护失败

C++ 程序崩溃,程序接收信号EXC_坏访问,无法访问内存。原因:地址0x00000000处的内核保护失败,c++,pthreads,exc-bad-access,C++,Pthreads,Exc Bad Access,我的程序因以下原因崩溃: Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_PROTECTION_FAILURE at address: 0x00000000 当我使用gdb的回溯时我得到: #0 0x0000e5f3 in std::__1::__tree_is_left_child<std::__1::__tree_node_base<void*>*> ()

我的程序因以下原因崩溃:

Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
当我使用
gdb的回溯时
我得到:

#0  0x0000e5f3 in std::__1::__tree_is_left_child<std::__1::__tree_node_base<void*>*> () at 

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/__tree:67
#1  0x0000e5f3 in application_manager::ApplicationManagerImpl::DecreaseMessageChain (this=<value temporarily unavailable, due to optimizations>) at __tree:158
#2  0x0002f942 in application_manager::commands::CommandResponseImpl::IsPendingResponseExist (this=<value temporarily unavailable, due to optimizations>) at src/components/application_manager/src/commands/command_response_impl.cc:100
#3  0x0005c638 in application_manager::commands::ShowResponse::Run (this=0xa4d450) at  src/components/application_manager/src/commands/mobile/show_response.cc:62
#4  0x0000b762 in utils::SharedPtr<application_manager::commands::Command>::operator-> () at src/components/utils/include/utils/shared_ptr.h:1138
#5  0x0000b762 in application_manager::ApplicationManagerImpl::ManageMobileCommand (this=<value temporarily unavailable, due to optimizations>, message=<value temporarily unavailable, due to optimizations>) at src/components/application_manager/src/application_manager_impl.cc:158
#6  0x0006580c in application_manager::commands::ResponseFromHMI::SendResponseToMobile (this=0xa4c9d0, message=@0xa4c9d4) at src/components/application_manager/src/commands/hmi/response_from_hmi.cc:67
#7  0x00073f2f in application_manager::commands::UIShowResponse::Run (this=0xa4c9d0) at src/components/application_manager/src/commands/hmi/ui_show_response.cc:52
#8  0x0000d3ba in utils::SharedPtr<application_manager::commands::Command>::operator-> () at src/components/utils/include/utils/shared_ptr.h:1202
#9  0x0000d3ba in application_manager::ApplicationManagerImpl::ManageHMICommand (this=0xb041ee20, message=<value temporarily unavailable, due to optimizations>) at src/components/application_manager/src/application_manager_impl.cc:158
#10 0x0001594c in application_manager::ApplicationManagerImpl::ProcessMessageFromHMI (this=<value temporarily unavailable, due to optimizations>, message=<value temporarily unavailable, due to optimizations>) at src/components/application_manager/src/application_manager_impl.cc:1412
#11 0x0002938f in utils::SharedPtr<application_manager::Message>::dropReference () at src/components/application_manager/src/from_hmh_thread_impl.cc:62
#12 0x0002938f in utils::SharedPtr<application_manager::Message>::~SharedPtr () at src/components/application_manager/src/from_hmh_thread_impl.cc:220
#13 0x0002938f in utils::SharedPtr<application_manager::Message>::~SharedPtr () at src/components/utils/include/utils/shared_ptr.h:219
#14 0x0002938f in application_manager::FromHMHThreadImpl::threadMain (this=0xa4d2f0) at src/components/application_manager/src/from_hmh_thread_impl.cc:158
#15 0x00341971 in (anonymous namespace)::threadFunc (closure=0xa4d2f0) at src/components/utils/src/threads/posix_thread.cc:44
#16 0x955cf5fb in _pthread_body ()
#17 0x955cf485 in _pthread_start ()
#18 0x955d4cf2 in thread_start ()

这似乎表明函数应该从堆栈中弹出并返回true。如果需要,我会有更多详细的日志-我不确定如何继续调试这个问题。我知道
0x00000000
是一个
空指针解引用
,但它似乎不是很明显。我以前也遇到过类似的错误,用-O3编译似乎隐藏了它。。这种情况在32位和64位时发生,代码是用
Clang 5.0

编译的,您没有在擦除操作上重置
j
迭代器:

i->second.erase(j);
使
j
迭代器无效

您需要这样做:

j = i->second.erase(j);
更重要的是,跳过增量,这意味着将其移动到循环体中的else条件。大概是这样的:

if (0 == (*it->second).counter()) 
{
    // do your thing, then..

    j = i->second.erase(j);
}
else
{   
    ++j;
}

而完全失去for-j循环,取而代之的是while循环,因为这就是没有增量步骤的全部。仔细查看您的代码,在错误的擦除之前,您有两个嵌套级别,因此您可能需要两个其他条件,或者不需要任何条件和一个
continue
j=i->second.erase()之后

您没有在擦除操作上重置
j
迭代器:

i->second.erase(j);
使
j
迭代器无效

您需要这样做:

j = i->second.erase(j);
更重要的是,跳过增量,这意味着将其移动到循环体中的else条件。大概是这样的:

if (0 == (*it->second).counter()) 
{
    // do your thing, then..

    j = i->second.erase(j);
}
else
{   
    ++j;
}

而完全失去for-j循环,取而代之的是while循环,因为这就是没有增量步骤的全部。仔细查看您的代码,在错误的擦除之前,您有两个嵌套级别,因此您可能需要两个其他条件,或者不需要任何条件和一个
continue
j=i->second.erase()之后

不是因为堆栈最初是空的,而您正试图弹出它吗?还有,这句话:“我以前遇到过类似的错误,用-O3编译似乎可以解决它。”-它可能没有解决问题,只是隐藏了它。用-O3编译并不能解决您的问题。它只是把它藏起来了。有时优化会“修复”bug(但不是真的!),有时它会暴露bug(在更高的优化级别下,显然可以使用-O0中断的代码)(:我并不认为它确实解决了问题。可能的问题是,您试图在对容器进行迭代时操纵容器的内容。不是因为堆栈最初是空的,您试图弹出它吗?还有,这句话:“我以前遇到过类似的错误,使用-O3编译似乎可以解决它。”-它可能没有解决问题,只是隐藏了问题。使用-O3编译并没有解决问题。它只是隐藏了问题。有时优化“修复”了错误(但不是真的!),有时它会暴露错误(显然与-O0一起工作的代码在更高的优化下会中断)。是的,语义(:我并不认为它确实解决了问题。可能的问题是,您试图在对容器进行迭代时操纵容器的内容。