Valgrind发现我不理解的错误

时间:2019-04-08 15:25:28

标签: c arrays bounds

我编写了以下函数

void x_dealiasing(int scounts, int nx, int nxd, FFT_SCALAR *u) {
    /* scounts = initial number of ny*nz modes */
    int stride_x, placeholder=0;
    int mode, i;
    for ( mode =0; mode < scounts; mode++) {
        stride_x = mode*nxd*2;
        for ( i = 0; i < 2*nx; i++) {
            u[placeholder] = u[stride_x+i];
            placeholder++;
            //printf("u[%d]= %g\n", placeholder, u[placeholder]);
        }
    }
}

我用Valgrind测试了程序,发现一个错误。 报告说

=6084== Invalid write of size 8
==6084==    at 0x410BBF: x_dealiasing (fft_support.c:62)
==6084==    by 0x40F852: convol_trasp_1convol_trasp (convol_trasp.c:2250)
==6084==    by 0x414FAC: dnsdirect_1buildrhs (dnsdirect.c:2187)
==6084==    by 0x40EFF0: main (channel_mpi.c:3075)
==6084==  Address 0x24b09b98 is 0 bytes after a block of size 294,920 alloc'd
==6084==    at 0x4C29B7E: malloc (vg_replace_malloc.c:299)
==6084==    by 0x40E6B4: main (channel_mpi.c:2667)
==6084== 

不幸的是,这是我第一次使用Valgrind,并且我只知道错误出在fft_support.c:62 -> u[placeholder] = u[stride_x+i];中 但是我不明白这是什么错误。

有人有一些提示或建议吗?

谢谢

0 个答案:

没有答案