gpt4 book ai didi

c++ - 在有足够空间的情况下加载到 Array 会导致 Stack Smashing?

转载 作者:行者123 更新时间:2023-11-28 04:17:48 25 4
gpt4 key购买 nike

当执行下面的代码时,我得到一个Stack Smashing错误。

const uint size = 62;

...
for (int i=0; i < 10; ++i){
// mask = elements != zero
// input = epi32 m512 data containing 1 byte values
_mm512_mask_compress_epi32(input, mask, input);
// get just elements != 0 as previous mask.
__mmask16 mask1 = _mm512_cmpneq_epi32_mask(compressed, _mm512_setzero_epi32());
// append the non-zero elements to the uchar*
_mm512_mask_cvtusepi32_storeu_epi8((uchar*)str+pos, mask1, compressed); // uncommenting = no error, truncating mask = no error

// add size of the inserted elements by counting 1's in mask
pos += sizeOfInsertion;

// print the position of the pointer AFTER storing
void* pp = (void*) ((uchar*) str + pos);
std::cout << pp << std::endl;
}

为了调查这个问题,我在插入元素时检查了指针的位置。在开头 (指向 str[0]) 我有 0x7ffce3468d30,在结尾 0x7ffce3468d69。减去这些地址我得到 3E = 62。所以它应该适合声明的数组。将掩码移动 1(截断一个元素),它不会引发错误。

最佳答案

失败在于压缩。我不介意将不匹配掩码的值归零,因此数据不会连续存储,因此堆栈会溢出。

简而言之:

_mm512_maskz_compress_epi32(mask, input);

成功了。

关于c++ - 在有足够空间的情况下加载到 Array 会导致 Stack Smashing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56214886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com