|
From: Duncan S. <bal...@fr...> - 2005-05-03 11:23:59
|
>From the manual: "3.3.6 Overlapping source and destination blocks The following C library functions copy some data from one memory block to another (or something similar): memcpy(), strcpy(), strncpy(), strcat(), strncat(). The blocks pointed to by their src and dst pointers aren't allowed to overlap. Memcheck checks for this. For example: ==27492== Source and destination overlap in memcpy(0xbffff294, 0xbffff280, 21) ==27492== at 0x40026CDC: memcpy (mc_replace_strmem.c:71) ==27492== by 0x804865A: main (overlap.c:40) ==27492== by 0x40246335: __libc_start_main (../sysdeps/generic/libc-start.c:129) ==27492== by 0x8048470: (within /auto/homes/njn25/grind/head6/memcheck/tests/overlap) ==27492== You don't want the two blocks to overlap because one of them could get partially trashed by the copying." Maybe it's worth giving more of an explanation here. I've noticed while floating around on the internet that people thing valgrind is just being pedantic when giving this warning and target < source. There are two problems: (1) if copying is done from largest address to smallest address. I don't know of any memcpy that does this. (2) if memcpy zeroes out the target before copying. This has been shown to improve the performance of memcpy on some intel architectures, due to cache effects. Of course it is fatal if there is any overlap between source and target. Most memcpy's don't do this kind of trick, but it's worth keeping in mind. All the best, Duncan. |