我正在我的iOS应用程序上写iOS。当我叫v->assign(anotherVec.begin(), anotherVec.end())
时,它总是给我看malloc: Incorrect checksum for freed object 0x7fe87824ea00: probably modified after being freed. Corrupt value: 0x0
。v
是一个vector<double>
指针,崩溃前向量大小为0。anotherVec
也是vector<double>
,它的大小是208个。释放的对象地址每次都不同。应用程序内存似乎足够了。
这里是STL向量中的崩溃函数和位置,我粘贴它只是为了显示它在STL代码中崩溃的位置:
template <class _Tp, class _Allocator>
template <class _ForwardIterator>
typename enable_if
<
__is_cpp17_forward_iterator<_ForwardIterator>::value &&
is_constructible<
_Tp,
typename iterator_traits<_ForwardIterator>::reference>::value,
void
>::type
vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
{
size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__new_size <= capacity())
{
_ForwardIterator __mid = __last;
bool __growing = false;
if (__new_size > size())
{
__growing = true;
__mid = __first;
_VSTD::advance(__mid, size());
}
pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
if (__growing)
__construct_at_end(__mid, __last, __new_size - size());
else
this->__destruct_at_end(__m);
}
else
{
__vdeallocate();
__vallocate(__recommend(__new_size)); // Crashes here!!!!!!
__construct_at_end(__first, __last, __new_size);
}
__invalidate_all_iterators();
}
我正在用Apple Clang 12.0.x和13.0.x Xcode运行这个程序。我的编译选项是-Os --std=c++11 -fPIC -pthread -fno-exceptions
。在不同的数据、iphones和iOS版本的用户中,这一比例约为0.01%。
我的macOS版本是12.1
。
所以我想知道:
Corrupt value: 0x0
是什么意思?我搜索了几个小时,但没有找到任何解释。,
发布于 2022-04-25 08:06:51
地址消毒剂真是个锋利的工具。在我的隔离演示应用程序中使用它,它显示了几个内存问题,其中一个问题是anotherVec
可能会在某些情况下导致索引超出限制的问题。修好后,assign
的崩溃就消失了。随着所有问题的解决,我们在模块中收集到的崩溃在主应用程序上变得不可复制。
使用ASan,我甚至在我的应用程序中发现了其他模块的更多问题。我向同事宣布了他们的情况,这也解决了他们的事故。
然而,我仍然找不到Corrupt value: 0x0
的意思。欢迎任何信息,非常欢迎!
https://stackoverflow.com/questions/71928838
复制相似问题