From 9e8a1699099f9aea5da11064e3aa9387ae9cffc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Thu, 7 Mar 2013 11:32:02 +0100 Subject: [PATCH] Fix copying overlapping comment Reformating block comments with -fca option triggered memcpy() on overlapping areas. E.g. comment: /* Some statement. Unless it's special, arrange * to break the line. */ from indent-2.2.11/indent.c hits it: $ valgrind -- ./indent -o /dev/null -fca indent.c Memcheck, a memory error detector Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al. Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info Command: ./indent -o /dev/null -fca indent.c Source and destination overlap in memcpy(0x4c2c3c4, 0x4c2c3c9, 6) at 0x4A0A230: memcpy@@GLIBC_2.14 (mc_replace_strmem.c:882) by 0x404EA7: print_comment (comments.c:857) by 0x40EB92: handle_token_comment (handletoken.c:2119) by 0x40EF38: handle_the_token (handletoken.c:2315) by 0x401FDB: indent_main_loop (indent.c:628) by 0x4021CD: indent (indent.c:715) by 0x402869: indent_single_file (indent.c:960) by 0x4028F1: indent_all (indent.c:992) by 0x4029E5: main (indent.c:1054) --- src/comments.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/comments.c b/src/comments.c index 01776e8..2ee8fc6 100644 --- a/src/comments.c +++ b/src/comments.c @@ -854,7 +854,7 @@ begin_line: save_length--; } - (void) memcpy (e_com, save_ptr, save_length); + (void) memmove (e_com, save_ptr, save_length); text_on_line = e_com; e_com += save_length; -- 1.8.1.4