bug-indent
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fix copying overlapping comment


From: Petr Písař
Subject: [PATCH] Fix copying overlapping comment
Date: Thu, 7 Mar 2013 11:45:29 +0100

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]