Bug 278502

Summary: Valgrind confuses memcpy() and memmove()
Product: [Developer tools] valgrind Reporter: Tavian Barnes <tavianator>
Component: memcheckAssignee: Julian Seward <jseward>
Status: RESOLVED DUPLICATE    
Severity: normal CC: tom
Priority: NOR    
Version: 3.6 SVN   
Target Milestone: ---   
Platform: unspecified   
OS: Unspecified   
Latest Commit: Version Fixed In:

Description Tavian Barnes 2011-07-25 20:47:04 UTC
(Note: this applies to version 3.6.1 but that isn't an option.)

Programs that call memmove() with overlapping arguments get a warning about overlapping arguments to memcpy(), while programs with buggy calls to memcpy() get no such warning.  Testcase:

$ cat foo.c
#include <string.h>
#include <stdio.h>

int
main()
{
  char test[] = " This is a test.";
  memmove(test, test + 1, 5);
  printf("%s\n", test);
  return 0;
}
$ gcc -Wall -g foo.c && valgrind -v ./a.out
==13429== Memcheck, a memory error detector
==13429== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==13429== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==13429== Command: ./a.out
==13429== 
--13429-- Valgrind options:
--13429--    -v
--13429-- Contents of /proc/version:
--13429--   Linux version 2.6.39-ARCH (thomas@evey) (gcc version 4.6.1 (GCC) ) #1 SMP PREEMPT Sat Jul 9 14:57:41 CEST 2011
--13429-- Arch and hwcaps: AMD64, amd64-sse3-cx16
--13429-- Page sizes: currently 4096, max supported 4096
--13429-- Valgrind library directory: /usr/lib/valgrind
--13429-- Reading syms from /home/tavianator/code/a.out (0x400000)
--13429-- Reading syms from /lib/ld-2.14.so (0x4000000)
--13429-- Reading syms from /usr/lib/valgrind/memcheck-amd64-linux (0x38000000)
--13429--    object doesn't have a symbol table
--13429--    object doesn't have a dynamic symbol table
--13429-- Reading suppressions file: /usr/lib/valgrind/default.supp
--13429-- REDIR: 0x4016a30 (strlen) redirected to 0x3805f707 (???)
--13429-- Reading syms from /usr/lib/valgrind/vgpreload_core-amd64-linux.so (0x4a21000)
--13429--    object doesn't have a symbol table
--13429-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so (0x4c22000)
--13429--    object doesn't have a symbol table
==13429== WARNING: new redirection conflicts with existing -- ignoring it
--13429--     new: 0x04016a30 (strlen              ) R-> 0x04c26d40 strlen
--13429-- REDIR: 0x4016770 (index) redirected to 0x4c269a0 (index)
--13429-- REDIR: 0x4016920 (strcmp) redirected to 0x4c27900 (strcmp)
--13429-- Reading syms from /lib/libc-2.14.so (0x4e2b000)
--13429--    object doesn't have a symbol table
--13429-- REDIR: 0x4ea92e0 (rindex) redirected to 0x4c26790 (rindex)
--13429-- REDIR: 0x4eaa5c0 (memcpy) redirected to 0x4c27a00 (memcpy)
==13429== Source and destination overlap in memcpy(0x7ff000270, 0x7ff000271, 5)
==13429==    at 0x4C27A66: memcpy (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==13429==    by 0x400577: main (foo.c:8)
==13429== 
--13429-- REDIR: 0x4ea77b0 (strlen) redirected to 0x4c26ce0 (strlen)
This  is a test.
--13429-- REDIR: 0x4ea24e0 (free) redirected to 0x4c25500 (free)
==13429== 
==13429== HEAP SUMMARY:
==13429==     in use at exit: 0 bytes in 0 blocks
==13429==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==13429== 
==13429== All heap blocks were freed -- no leaks are possible
==13429== 
==13429== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 7 from 7)
==13429== 
==13429== 1 errors in context 1 of 1:
==13429== Source and destination overlap in memcpy(0x7ff000270, 0x7ff000271, 5)
==13429==    at 0x4C27A66: memcpy (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==13429==    by 0x400577: main (foo.c:8)
==13429== 
--13429-- 
--13429-- used_suppression:      7 dl-hack3-cond-1
==13429== 
==13429== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 7 from 7)
$ uname -a
Linux superluminal 2.6.39-ARCH #1 SMP PREEMPT Sat Jul 9 14:57:41 CEST 2011 x86_64 Intel(R) Xeon(R) CPU X5660 @ 2.80GHz GenuineIntel GNU/Linux
Comment 1 Tom Hughes 2011-07-25 21:25:54 UTC
This will be caused by the whole memcpy/memove funkyness in glibc 2.14 that we are dealing with as bug #275284.

*** This bug has been marked as a duplicate of bug 275284 ***