https://bugs.kde.org/show_bug.cgi?id=401284
Bug ID: 401284 Summary: False positive "Source and destination overlap in strncat" Product: valgrind Version: unspecified Platform: Other OS: Linux Status: REPORTED Severity: normal Priority: NOR Component: memcheck Assignee: jsew...@acm.org Reporter: l...@ncbi.nlm.nih.gov Target Milestone: --- SUMMARY Valgrind reports: Source and destination overlap in strncat(0x4c33045, 0x4c33040, 5) which is, given the argument values, an impossible situation: strncat() will not take more than 5 bytes from the location pointed to by second argument, 0x4c33040, that is, the range 0x4c33040-0x4c33044 (if not fewer, should a '\0' be encountered within), but the destination address is out of that range (yet indeed right adjacent to the source area). But there's no error here. STEPS TO REPRODUCE #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { size_t len = strlen(argv[1]); char* buf = (char*) malloc(2 * len + 1); memcpy(buf, argv[1], len + 1); strncat(buf + len, buf, len); printf("%s\n", buf); free(buf); return 0; } OBSERVED RESULT $ gcc -Wall -o vbug vbug.c $ ./vbug hello hellohello $ valgrind ./vbug hello ==10915== Memcheck, a memory error detector ==10915== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==10915== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info ==10915== Command: ./vbug hello ==10915== ==10915== Source and destination overlap in strncat(0x4c33045, 0x4c33040, 5) ==10915== at 0x4A08A76: strncat (vg_replace_strmem.c:344) ==10915== by 0x4006D0: main (in /home/lavr/vbug) ==10915== hellohello ==10915== ==10915== HEAP SUMMARY: ==10915== in use at exit: 0 bytes in 0 blocks ==10915== total heap usage: 1 allocs, 1 frees, 11 bytes allocated ==10915== ==10915== All heap blocks were freed -- no leaks are possible ==10915== ==10915== For counts of detected and suppressed errors, rerun with: -v ==10915== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 6 from 5) EXPECTED RESULT No errors SOFTWARE/OS VERSIONS Linux: uname -a Linux hostname 2.6.32-754.6.3.el6.x86_64 #1 SMP Tue Oct 9 17:27:49 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux -- You are receiving this mail because: You are watching all bug changes.