Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Valgrind Error Report

Reply
Thread Tools

Valgrind Error Report

 
 
Mohsen
Guest
Posts: n/a
 
      09-26-2006
Dear all,
I am running a program and in one of the functions I have to sort the
data of an array as follows:
..
..
..
for (m=0;m<M;++m) //Sort
{
k=m;
for (j=m+1;j<M;++j)
{
if (DT[j]<DT[k]) k=j;
}
Temp=DT[m];
DT[m]=DT[k]; <<-----The 'Valgrind' gives error in this line
DT[k]=Temp;
}
..
..
..

When I check my program by 'Valgrind', it gives me the following
sentence which is pointing to error in the line that I have pointed in
the program.
==11285==
==11285== Source and destination overlap in memcpy(0x4A33358,
0x4A33358, 400)
==11285== at 0x4906C4A: memcpy (mac_replace_strmem.c:394)
==11285== by 0x4014F8: SP(Record*, Record*) (925.cpp:601)
==11285== by 0x40EDF5: main (925.cpp:197)

Is it really an error? I have just substituted the elements of an array!

 
Reply With Quote
 
 
 
 
Dave Townsend
Guest
Posts: n/a
 
      09-26-2006

"Mohsen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Dear all,
> I am running a program and in one of the functions I have to sort the
> data of an array as follows:
> .
> .
> .
> for (m=0;m<M;++m) //Sort
> {
> k=m;
> for (j=m+1;j<M;++j)
> {
> if (DT[j]<DT[k]) k=j;
> }
> Temp=DT[m];
> DT[m]=DT[k]; <<-----The 'Valgrind' gives error in this line
> DT[k]=Temp;
> }
> .
> .
> .
>
> When I check my program by 'Valgrind', it gives me the following
> sentence which is pointing to error in the line that I have pointed in
> the program.
> ==11285==
> ==11285== Source and destination overlap in memcpy(0x4A33358,
> 0x4A33358, 400)
> ==11285== at 0x4906C4A: memcpy (mac_replace_strmem.c:394)
> ==11285== by 0x4014F8: SP(Record*, Record*) (925.cpp:601)
> ==11285== by 0x40EDF5: main (925.cpp:197)
>
> Is it really an error? I have just substituted the elements of an array!
>

In this case its harmless. I believe valgrind issues warnings about
overlapping
src/dst when using memcpy (which has undefined behavior in that situation),
you should use memmove when src/dst overlap.
In this case src and dst are the same. But why is that,shouldn't you only
be swapping elements which are actually different ?
Shouldn't the line be if (DT[j]<=DT[k]) k=j;




 
Reply With Quote
 
 
 
 
Mohsen
Guest
Posts: n/a
 
      09-26-2006
Hi,
The values af my array can not be the same and for that reason I have
written:
if (DT[j]<DT[k]) k=j;
Best,
Mohsen

Dave Townsend wrote:
> "Mohsen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > Dear all,
> > I am running a program and in one of the functions I have to sort the
> > data of an array as follows:
> > .
> > .
> > .
> > for (m=0;m<M;++m) //Sort
> > {
> > k=m;
> > for (j=m+1;j<M;++j)
> > {
> > if (DT[j]<DT[k]) k=j;
> > }
> > Temp=DT[m];
> > DT[m]=DT[k]; <<-----The 'Valgrind' gives error in this line
> > DT[k]=Temp;
> > }
> > .
> > .
> > .
> >
> > When I check my program by 'Valgrind', it gives me the following
> > sentence which is pointing to error in the line that I have pointed in
> > the program.
> > ==11285==
> > ==11285== Source and destination overlap in memcpy(0x4A33358,
> > 0x4A33358, 400)
> > ==11285== at 0x4906C4A: memcpy (mac_replace_strmem.c:394)
> > ==11285== by 0x4014F8: SP(Record*, Record*) (925.cpp:601)
> > ==11285== by 0x40EDF5: main (925.cpp:197)
> >
> > Is it really an error? I have just substituted the elements of an array!
> >

> In this case its harmless. I believe valgrind issues warnings about
> overlapping
> src/dst when using memcpy (which has undefined behavior in that situation),
> you should use memmove when src/dst overlap.
> In this case src and dst are the same. But why is that,shouldn't you only
> be swapping elements which are actually different ?
> Shouldn't the line be if (DT[j]<=DT[k]) k=j;


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Valgrind says "Invalid read of size 4". What's the problem? hvaisane@cc.joensuu.fi C++ 2 02-17-2005 12:45 PM
Problems with valgrind Andreas Andersen C++ 2 01-18-2005 03:06 PM
Checking for memory leaks: valgrind versus insure++ rsina C++ 2 11-29-2004 11:04 AM
getting rid of error report/ dont send error report Windows XP Computer Support 8 05-10-2004 06:34 PM
leak detected using valgrind Alexandre C++ 1 11-13-2003 07:43 AM



Advertisments