# Use memmove instead of memcpy for overlapping areas

2 messages from 2006-10-30 to 2006-10-31. Participants: Edgar Toernig, Junio C Hamano.
Thread: https://gitlist.dev/t/43159

## Edgar Toernig, 2006-10-30 21:26

Subject: Use memmove instead of memcpy for overlapping areas
Message-ID: <20061030222615.1e38908b.froese@gmx.de>
URL: https://gitlist.dev/e/20061030222615.1e38908b.froese%40gmx.de

```
There may be more - this is just the result of a quick eye-grep
for memcpy(x, x+i).

diff --git a/imap-send.c b/imap-send.c
index 16804ab..88d635f 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -272,7 +272,7 @@ buffer_gets( buffer_t * b, char **s )
 				n = b->bytes - start;
 
 				if (n)
-					memcpy( b->buf, b->buf + start, n );
+					memmove( b->buf, b->buf + start, n );
 				b->offset -= start;
 				b->bytes = n;
 				start = 0;
diff --git a/index-pack.c b/index-pack.c
index e33f605..a275982 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -61,7 +61,7 @@ static void * fill(int min)
 		die("cannot fill %d bytes", min);
 	if (input_offset) {
 		SHA1_Update(&input_ctx, input_buffer, input_offset);
-		memcpy(input_buffer, input_buffer + input_offset, input_len);
+		memmove(input_buffer, input_buffer + input_offset, input_len);
 		input_offset = 0;
 	}
 	do {


```

## Junio C Hamano, 2006-10-31 01:37

Subject: Re: Use memmove instead of memcpy for overlapping areas
Message-ID: <7vpsc9s1t9.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vpsc9s1t9.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20061030222615.1e38908b.froese@gmx.de>

```
Edgar Toernig <froese@gmx.de> writes:

> There may be more - this is just the result of a quick eye-grep
> for memcpy(x, x+i).

Thanks.  Sign-off?

Among many false hit, 

$ git grep 'memcpy.*( *\(.*\),.*\1.*+'

gives this one:

builtin-unpack-objects.c:               memcpy(buffer, buffer + offset, len);

```
