diff mbox series

locale: use memmove for potentially overlapping data

Message ID xnh68jlqpi.fsf@greed.delorie.com
State New
Headers show
Series locale: use memmove for potentially overlapping data | expand

Commit Message

DJ Delorie Nov. 7, 2024, 2:31 a.m. UTC
While this may happen to work for current glibc, it's bad practice.
Use memmove instead of memcpy just in case, and because it's
more correct.

Comments

Paul Eggert Nov. 7, 2024, 3:57 a.m. UTC | #1
On 2024-11-06 18:31, DJ Delorie wrote:
> -	  memcpy (ctx->buffer, &ctx->buffer[64], left_over);
> +	  memmove (ctx->buffer, &ctx->buffer[64], left_over);

left_over <= 64 so it's not an overlapping move. Making the change will 
make the code more confusing, as readers might wonder "Why use memmove 
when the move is non-overlapping?"

> Use memmove instead of memcpy just in case

By that argument, shouldn't every call to memcpy be replaced by memmove?
diff mbox series

Patch

diff --git a/locale/programs/md5.c b/locale/programs/md5.c
index 753b91e9a8..f198223656 100644
--- a/locale/programs/md5.c
+++ b/locale/programs/md5.c
@@ -170,7 +170,7 @@  __md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
 	{
 	  __md5_process_block (ctx->buffer, 64, ctx);
 	  left_over -= 64;
-	  memcpy (ctx->buffer, &ctx->buffer[64], left_over);
+	  memmove (ctx->buffer, &ctx->buffer[64], left_over);
 	}
       ctx->buflen = left_over;
     }