473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Valgrind Error Report

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!

Sep 26 '06 #1
2 1788

"Mohsen" <ja*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr 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;


Sep 26 '06 #2
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" <ja*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr 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;
Sep 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jerald | last post by:
Running python 2.3.4 on valgrind (a tool like purify which checks the use of uninitialized memory, etc), gives a lot of errors. See below. jfj@cluster:~/> python -V Python 2.3.4...
0
by: Sitsofe Wheeler | last post by:
Hello, I am using a threaded C program and each thread creates its own connection to mysql database using mysql_init(). When I run Valgrind on the program it reports that there has been a small...
2
by: Andreas Andersen | last post by:
Hi I have been using valgrind to debug a program I have written in C++ and it has been very helpful in eliminating memory errors/leaks. However, I just recently discovered a bug and from what I...
2
by: hvaisane | last post by:
Valgrind says ==11604== Invalid read of size 4 ==11604== at 0x8048ABB: main (foo.cc:36) ==11604== Address 0x1B92415C is 4 bytes inside a block of size 8 free'd ==11604== at 0x1B90514F:...
1
by: mfried | last post by:
Hi all, I'm testing an application using valgrind 3.2.0 unter Linux kernel 2.4. When the test are finished and the app terminates valgrind gives the error: --15631:0:aspacem Valgrind: FATAL:...
4
by: Simple Simon | last post by:
It's entirely possible that I'm completely in the wrong line of work, but I don't see what Valgrind is complaining about in this code. Invalid read/writes? If I free the within main(), rather...
3
by: Esa A E Peuha | last post by:
Running Python 2.5.1 under Valgrind is interesting; just starting it and then pressing Ctrl-D produces this: ==27082== ERROR SUMMARY: 713 errors from 56 contexts (suppressed: 10 from 1)...
0
by: Salvatore Iovene | last post by:
Hi, I'm using the pexpect module to spawn some processes in a testing environment. pexpect uses, internally, os.execv. What I need to do is valgrind python and get memory leaks from the spawned...
2
by: tvnaidu | last post by:
valgrind error - "failed to start tool 'memcheck' for platform x86-linux" no such file or dir copied all lib and bin files which are generated after I compiled valgrind package, when I run my exe...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.