NOOB Q. Valgrind头痛。条件跳转或移动取决于未初始化的值?

时间:2018-03-19 20:26:01

标签: valgrind

  

我正在编写一个程序Playfair Cipher。你可能听说过它。这是一个程序中我已经制作了5x5矩阵(2d数组)的地方,它已经包含很少的字母(键字符串)。它是从(0,0)逐行填充的。下一步是用宏ALPHA(第3行)中包含的字母填充矩阵的其余部分,这样如果字母已经在矩阵中,它将不会再次进入矩阵。为什么我从valgrind那里收到这条消息?图片下方的代码。 P.S。:大学生从C开始。请记住这一点。

for(int i=0; i<25; i++){
    int counter8=0;
    char c=ALPHA[i];
    for(int y=0; y<5; y++){
        for(int x=0; x<5; x++){
            if(c==matrix[y][x]){
                counter8++;

            }

        }
    }   
    if(counter8==0){
        for(int y=0; y<5; y++){
            for(int x=0; x<5; x++){
                if((x!=0  && !isalpha(matrix[y][x]) &&  isalpha(matrix[y][x-1])) || 
                   (x==0 && y!=0 && !isalpha(matrix[y][x]) &&  isalpha(matrix[y-1][4]))){
                    matrix[y][x]=c; 
                }

            }
        }
    }   
}

valgrind的图片 - &gt;&gt;&gt; valgrind outputs this&lt;&lt;&lt; -

==4517== Conditional jump or move depends on uninitialised value(s)
==4517==    at 0x401463: playfair_encrypt (in /home/samuel/prog-
2018/ps2/output)
==4517==    by 0x406B4D: main (in /home/samuel/prog-2018/ps2/output)
==4517==  Uninitialised value was created by a stack allocation
==4517==    at 0x400766: playfair_encrypt (in /home/samuel/prog-
2018/ps2/output)
==4517== 
==4517== Use of uninitialised value of size 8
==4517==    at 0x401503: playfair_encrypt (in /home/samuel/prog-
2018/ps2/output)
==4517==    by 0x406B4D: main (in /home/samuel/prog-2018/ps2/output)
==4517==  Uninitialised value was created by a stack allocation
==4517==    at 0x400766: playfair_encrypt (in /home/samuel/prog-
2018/ps2/output)
==4517== 
==4517== Use of uninitialised value of size 8
==4517==    at 0x4015C0: playfair_encrypt (in /home/samuel/prog-
2018/ps2/output)
==4517==    by 0x406B4D: main (in /home/samuel/prog-2018/ps2/output)
==4517==  Uninitialised value was created by a stack allocation
==4517==    at 0x400766: playfair_encrypt (in /home/samuel/prog-
2018/ps2/output)
==4517== 
==4517== 
==4517== HEAP SUMMARY:
==4517==     in use at exit: 0 bytes in 0 blocks
==4517==   total heap usage: 11 allocs, 11 frees, 1,136 bytes 
allocated
==4517== 
==4517== All heap blocks were freed -- no leaks are possible
==4517== 
==4517== For counts of detected and suppressed errors, rerun with: -v
==4517== ERROR SUMMARY: 34 errors from 3 contexts (suppressed: 0 from 
0)

0 个答案:

没有答案