難しい方法でcを学びますが、作業します..次のコードがあります:
#include <stdio.h>
/* Warning: This program is wrong on purpose. */
int main()
{
int age = 10;
int height;
printf("I am %d years old.\n");
printf("I am %d inches tall.\n", height);
return 0;
}
今、私がvalgrindを実行するとき、私はそうします
valgrind --track-origins=yes ./ex4
そして、私はこれを取得します:
collin@ubuntu:~/learning$ valgrind --track-origins=yes ./ex4
==14332== Memcheck, a memory error detector
==14332== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==14332== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==14332== Command: ./ex4
==14332==
==14332== Use of uninitialised value of size 4
==14332== at 0x408C2AB: _itoa_word (_itoa.c:179)
==14332== by 0x408FB21: vfprintf (vfprintf.c:1654)
==14332== by 0x409681E: printf (printf.c:34)
==14332== by 0x4061934: (below main) (libc-start.c:260)
==14332== Uninitialised value was created by a stack allocation
==14332== at 0x8048422: main (ex4.c:6)
==14332==
==14332== Conditional jump or move depends on uninitialised value(s)
==14332== at 0x408C2B3: _itoa_word (_itoa.c:179)
==14332== by 0x408FB21: vfprintf (vfprintf.c:1654)
==14332== by 0x409681E: printf (printf.c:34)
==14332== by 0x4061934: (below main) (libc-start.c:260)
==14332== Uninitialised value was created by a stack allocation
==14332== at 0x8048422: main (ex4.c:6)
==14332==
==14332== Conditional jump or move depends on uninitialised value(s)
==14332== at 0x408CFE5: vfprintf (vfprintf.c:1654)
==14332== by 0x409681E: printf (printf.c:34)
==14332== by 0x4061934: (below main) (libc-start.c:260)
==14332== Uninitialised value was created by a stack allocation
==14332== at 0x8048422: main (ex4.c:6)
==14332==
==14332== Conditional jump or move depends on uninitialised value(s)
==14332== at 0x408D061: vfprintf (vfprintf.c:1654)
==14332== by 0x409681E: printf (printf.c:34)
==14332== by 0x4061934: (below main) (libc-start.c:260)
==14332== Uninitialised value was created by a stack allocation
==14332== at 0x8048422: main (ex4.c:6)
==14332==
==14332== Conditional jump or move depends on uninitialised value(s)
==14332== at 0x4091328: vfprintf (vfprintf.c:1654)
==14332== by 0x409681E: printf (printf.c:34)
==14332== by 0x4061934: (below main) (libc-start.c:260)
==14332== Uninitialised value was created by a stack allocation
==14332== at 0x8048422: main (ex4.c:6)
==14332==
==14332== Conditional jump or move depends on uninitialised value(s)
==14332== at 0x408D0B8: vfprintf (vfprintf.c:1654)
==14332== by 0x409681E: printf (printf.c:34)
==14332== by 0x4061934: (below main) (libc-start.c:260)
==14332== Uninitialised value was created by a stack allocation
==14332== at 0x8048422: main (ex4.c:6)
==14332==
==14332== Conditional jump or move depends on uninitialised value(s)
==14332== at 0x408D0F1: vfprintf (vfprintf.c:1654)
==14332== by 0x409681E: printf (printf.c:34)
==14332== by 0x4061934: (below main) (libc-start.c:260)
==14332== Uninitialised value was created by a stack allocation
==14332== at 0x8048422: main (ex4.c:6)
==14332==
I am -1097264588 years old.
I am 69169152 inches tall.
==14332==
==14332== HEAP SUMMARY:
==14332== in use at exit: 0 bytes in 0 blocks
==14332== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==14332==
==14332== All heap blocks were freed -- no leaks are possible
==14332==
==14332== For counts of detected and suppressed errors, rerun with: -v
==14332== ERROR SUMMARY: 46 errors from 7 contexts (suppressed: 0 from 0)
問題の場所を教えてくれるvalgrindingではなく、この「メインの下」のものを取得しているのはなぜですか? --track-origins=yes を実行すると、これを修正できると思いました。
助けに感謝します。
これは私が使用した私のMakefileです
CFLAGS=-Wall -g
clean:
rm -f ex4