Skip to contentSkip to conversation

Use memmove instead of memcpy for overlapping areas

PATCH Edgar Toernig 2 participants 2 messages Aug 11, 2016

lore
Share & tools
lore
#0 lore raw

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

imap-send.c +1 -1
index 16804ab..88d635f 100644
@@ -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;
index-pack.c +1 -1
index e33f605..a275982 100644
@@ -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 {
#1 lore raw
Quoted 2 lines · Edgar Toernig

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);