|
From: Santosh N. <san...@gm...> - 2011-03-29 01:27:39
|
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.
Thanks
Santosh
|
|
From: Florian K. <br...@ac...> - 2011-03-29 02:07:45
|
On 03/28/2011 09: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?
>
You might. Line 28 allocates memory but it does not initialize it.
matrix[row[ is initialized, of course, but matrix[row][0] etc.. is not.
Florian
|
|
From: Santosh N. <san...@gm...> - 2011-03-29 03:08:48
|
Hi Florian,
Thanks for the suggestion. As far as I know, this one of the ways of
declaring a 2D matrix in C. Please correct me if I am wrong. The
initialization happens in another nested for loop.
Thanks
Santosh
On Mon, Mar 28, 2011 at 9:07 PM, Florian Krohm <br...@ac...> wrote:
> On 03/28/2011 09: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?
> >
>
> You might. Line 28 allocates memory but it does not initialize it.
> matrix[row[ is initialized, of course, but matrix[row][0] etc.. is not.
>
> Florian
>
|
|
From: John R. <jr...@bi...> - 2011-03-29 03:42:02
|
> As far as I know, this one of the ways of declaring a 2D matrix in C. ... The initialization happens in another nested for loop. So far you have not shown the code that establishes a value for each matrix[row][j] when 0 <= j < size and 0 <= row < size. Memcheck's complaint is about the _use_ of an uninit value in a call to printf() which appears at line 42 of matrix1.c. (And furthermore, sizeof that uninit value is 8, not 4; although this may be an artifact that is internal to _itoa_word.) As a partial clue, memcheck tells you that the space for the uninit value was created by malloc() called from line 28 of matrix1.c. Whatever is on lines 29 through 41 did not store anything into [some portion of] that space. Hint: Immediately after the malloc, printf row and matrix[row] . Immediately after each assignment in the nested 'for' loop which you claim initializes the matrix, then printf the _address_ of the entry which was intialized on that iteration. Immediately before the printf on line 42 of matrix1.c, insert another printf which prints the _address_ of anything whose value is printed by line 42. Then compare addresses. -- |
|
From: David C. <dcc...@ac...> - 2011-03-29 04:52:42
|
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 dcc...@ac...
Chapman Consulting -- San Jose, CA
|
|
From: Santosh N. <san...@gm...> - 2011-03-29 13:33:29
|
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 <dcc...@ac...> 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 dcc...@ac...
> Chapman Consulting -- San Jose, CA
>
>
|
|
From: <gup...@ne...> - 2011-03-29 08:41:53
|
A memset immediately after the malloc but before the for loop should take care of this problem. The for loop may execute before your other nested initialization occurs. memset(matrix, 0, (size * sizeof(in))); Satya Sent from my Verizon Wireless BlackBerry -----Original Message----- From: Santosh Navale <san...@gm...> Date: Mon, 28 Mar 2011 22:08:00 To: Florian Krohm<br...@ac...> Cc: <val...@li...> Subject: Re: [Valgrind-users] Problem resolving a Valgrind reported error ------------------------------------------------------------------------------ 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 |
|
From: Santosh N. <san...@gm...> - 2011-03-29 13:34:45
|
Hi Satya, I have ensured that the initialization occurs before the data is used/printed. So I believe memset is not required. I could give this a try and see if it works. By the way, I figured out the error and it is a improper incrementing of a variable. Thanks Santosh On Tue, Mar 29, 2011 at 3:41 AM, <gup...@ne...> wrote: > A memset immediately after the malloc but before the for loop should take > care of this problem. The for loop may execute before your other nested > initialization occurs. > > memset(matrix, 0, (size * sizeof(in))); > > Satya > Sent from my Verizon Wireless BlackBerry > > -----Original Message----- > From: Santosh Navale <san...@gm...> > Date: Mon, 28 Mar 2011 22:08:00 > To: Florian Krohm<br...@ac...> > Cc: <val...@li...> > Subject: Re: [Valgrind-users] Problem resolving a Valgrind reported error > > > ------------------------------------------------------------------------------ > 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 > |
|
From: John C. <Joh...@no...> - 2011-03-29 10:23:10
|
Santosh,
Why not use calloc() instead of malloc()?
John
On 03/28/2011 07:08 PM, Santosh Navale wrote:
> Hi Florian,
>
> Thanks for the suggestion. As far as I know, this one of the ways of
> declaring a 2D matrix in C. Please correct me if I am wrong. The
> initialization happens in another nested for loop.
>
> Thanks
> Santosh
>
> On Mon, Mar 28, 2011 at 9:07 PM, Florian Krohm <br...@ac...
> <mailto:br...@ac...>> wrote:
>
> On 03/28/2011 09: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?
> >
>
> You might. Line 28 allocates memory but it does not initialize it.
> matrix[row[ is initialized, of course, but matrix[row][0] etc.. is
> not.
>
> Florian
>
>
>
> ------------------------------------------------------------------------------
> 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
> Val...@li...
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
|