473,721 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(0x4A3335 8,
0x4A33358, 400)
==11285== at 0x4906C4A: memcpy (mac_replace_st rmem.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 1817

"Mohsen" <ja*******@gmai l.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.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(0x4A3335 8,
0x4A33358, 400)
==11285== at 0x4906C4A: memcpy (mac_replace_st rmem.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*******@gmai l.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.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(0x4A3335 8,
0x4A33358, 400)
==11285== at 0x4906C4A: memcpy (mac_replace_st rmem.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
2948
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 jfj@cluster:~/> valgrind python ==10517== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
0
657
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 leak stemming from several mysql_init and one mysql_real_connect. I have read http://www.mysql.com/doc/en/Threaded_clients.html but despite adding my_thread_init(), my_thread_end() and linking against mysqlclient_r a leak is still reported. Here...
2
2551
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 can see it looks like some kind of memory problem. However, when I run it through valgrind no errors are reported and the bug seems to be gone! I print some status from the program and at some point this becomes wrong but when the program is run...
2
22818
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: operator delete(void*) (vg_replace_malloc.c:156) ==11604== by 0x804A1BA: __gnu_cxx::new_allocator<Foo>::deallocate(Foo*, unsigned) (new_allocator.h:86) ==11604== by 0x8049C08: std::_Vector_base<Foo, std::allocator<Foo> >::_M_deallocate(Foo*,...
1
2382
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: I/O error on /proc/self/maps --15631:0:aspacem Exiting now. My first thought was that I need more access rights on that file, but
4
5082
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 than within free_node_list(), Valgrind reports 0 leaks? OS: SuSE 9.3 Linux 2.6.11.4-21.11-default i686 i386 GCC: 3.3.5 20050117
3
2778
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) ==27082== malloc/free: in use at exit: 1,243,153 bytes in 508 blocks. ==27082== malloc/free: 3,002 allocs, 2,494 frees, 2,748,487 bytes allocated. ==27082== For counts of detected errors, rerun with: -v ==27082== searching for pointers to 508 not-freed...
0
1436
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 children (assuming that python doesn't leak :)). Here's a simple testcase: =================== leak.c:
2
9594
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 with valgrind, I am getting above error, any idea? lib/ -rw-r--r-- 1 0 0 27934 default.supp -rwxr-xr-x 1 0 0 4636305 cachegrind-x86-linux -rwxr-xr-x 1 0 0 4891451 callgrind-x86-linux...
0
9367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9131
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9064
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.