Hi David,
That is correct. I am printing matrix[i][j] at line 42. But I am
initializing the matrix between the lines 28 and 42.
I figured out the problem with a little help from my friend. Turns out I was
improperly incrementing a variable that I was using to malloc other arrays.
But the strange thing is this error is much after the Line 42. So I am not
sure if I was looking at the Valgrind output correctly.
Also now that my code is working, I ran Valgrind to test for errors and I
still get an error whereas my code is running properly. Is this a cause of
concern or does it depend on the error I am getting. Are all Valgrind errors
crucial or can some be ignored safely.
Thanks
Santosh
On Mon, Mar 28, 2011 at 10:44 PM, David Chapman <dcchap...@acm.org> wrote:
> On 3/28/2011 6:26 PM, Santosh Navale wrote:
>
> Hi,
>
> The following is the message I get when I run valgrind on my C code.
>
> ==16455== Use of uninitialised value of size 8
> ==16455== at 0x4E6A76B: _itoa_word (_itoa.c:195)
> ==16455== by 0x4E6B9B8: vfprintf (vfprintf.c:1613)
> ==16455== by 0x4E75869: printf (printf.c:35)
> ==16455== by 0x400830: main (matrix1.c:42)
> ==16455== Uninitialised value was created by a heap allocation
> ==16455== at 0x4C244E8: malloc (vg_replace_malloc.c:236)
> ==16455== by 0x400752: main (matrix1.c:28)
>
> From my understanding something on line 28 in the file matrix1.c is
> causing an error. When I look at the source code,
>
> matrix = (int **) malloc (size * sizeof(int *));
> for (row = 0; row < size; row++) {
> matrix[row] = (int *) malloc (size * sizeof(int));
> <------------------- Line 28
> }
>
> I do not see how this can be a problem. Am I missing something very
> fundamental?
>
> Any suggestion is appreciated.
>
>
> Line 28 is where the data is allocated; line 42 is where Valgrind says it
> is referenced before being initialized. From the call stack, it appears
> that you are trying to print some matrix[i][j] using a printf() call on line
> 42.
>
> --
> David Chapman dcchap...@acm.org
> Chapman Consulting -- San Jose, CA
>
>
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users