c - "Use of uninitialised value" despite of memset -
I assign a 2d array and use the memeset to fill it with zero.
# include & lt; Stdio.h & gt; #to & lt include, string.h & gt; #to & lt include, stdlib.h & gt; Zero main () {int m = 10; Int n = 10; Int ** array_2d; Array_2d = (int **) malloc (m * size (int *)); If (array_2d == NULL) {printf ("\ n malloc could not be arrayed 2d \ n"); Exit (1); } For (int i = 0; i & lt; m; i ++) {((array_2d) [i]) = malloc (n * sizeof (int)); Memset (((array_2d) [i]), 0, sizeof (n * sizeof (int)); } For (int i = 0; i & lt; 10; i ++) {for (int j = 0; j & lt; 10; j ++) {printf ("(% i,% i) =" , I, j); Fflush (stdout); Printf ("% i", array 2D [i] [ja]); } Printf ("\ n"); }}
Then I use Valgrind [1] to check memory errors I get the following error: conditional jump or move on unmanaged value (values) Depends
line 24 ( printf ("% i", array_2d [i] [j]);
). I always thought that there is a function to start the MEMAX arrames, how can I get rid of this error?
Thank you!
Valgrind output:
== 3485 == Memcheck, a memory editor detector = 3485 == Copyright (c) 2002-2009, and GNU GPLD, Julian Send Et al == 3485 == Valgrind-3.5.0-Using Debian and LibVEX; For copyright information, re-run with h == 3485 == Command: ./a.out == 3485 == (0,0) = 0 (0,1) === 3485 == The undefined value of the shape Use = 4 = = 3485 == 0x409E186: _itoa_word (_itoa.c: 195) == 3485 == 0x40A1AD1: vfprintf (vfprintf.c: 1613) == 3485 == 0x40A8FFF by: printf (printf.c: 35) == 3485 == 0x8048724: Main (playing_with_valgrind.c: 39) == 3485 == == 3485 == == 3485 == ---- Attach to debugger? --- [Return / N / N / Y / Y / C / C] ---- == 3485 == Conditional jump or move depends on uncontrolled value (s) == 3485 == 0x409E18E at: _itoa_word ( _itoa. C: 195) == 3485 == 0x40A1AD1: vfprintf (vfprintf.c: 1613) == 3485 == 0x40A8FFF by: printf (printf.c: 35) == 3485 == 0x8048724: main (playing_with_valgrind.c: 39)
[1] [gcc-cmd] valgrind --tool = memcheck --leak-check = yes --ho-reachable = yes --num-callers = 20 --track - Fds = yes --db-attach = yes ./a.out ./code>
GCC -STD = c99 -lm-wall -g3 play_with_valgrind.c < / Code>
On this line:
/ * sizeof ( N * Sizeof (int)) is a value of type size_t tains means that you are able to start only the size of the array (Akar_ti) * / Memetset (((Aaradeedeedeedi) [i]), 0, Akarf (N * Akarf (Int)));
It should be:
memset ((array_2d) [i]), 0, n * sizeof (int));
Comments
Post a Comment