加载到阵列中会导致堆栈粉碎,同时有足够的空间

Loading into Array causes Stack Smashing while having enough space?

本文关键字:空间 阵列 堆栈 加载      更新时间:2023-10-16

执行以下代码时,我会收到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;
}

为了调查此问题,我在插入元素时检查了指针的位置。在开始(pointing to str[0])时,我有0x7ffce3468d30,最后0x7ffce3468d69。减去这些地址我得到3E = 62。因此,它应该安装在已声明的数组中。将蒙版移动1(截断一个元素(,不会丢失错误。

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

简而言之:

_mm512_maskz_compress_epi32(mask, input);

使它起作用。