Message ID | xnh68jlqpi.fsf@greed.delorie.com |
---|---|
State | New |
Headers | show |
Series | locale: use memmove for potentially overlapping data | expand |
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 --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; }