locale: use memmove for potentially overlapping data
DJ Delorie
dj@redhat.com
Thu Nov 7 04:46:22 GMT 2024
Paul Eggert <eggert@cs.ucla.edu> writes:
>> - 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.
This is a result from a static analysis, and I - reading the code -
couldn't prove that to myself.
> Making the change will make the code more confusing, as readers might
> wonder "Why use memmove when the move is non-overlapping?"
It certainly *looks* overlapping. I would hate for someone to use that
code as an excuse to use memcpy in a situation that looks like that but
*is* overlapping.
>> Use memmove instead of memcpy just in case
>
> By that argument, shouldn't every call to memcpy be replaced by memmove?
Only the ones that are moving from one part of a buffer to another part
of the same buffer, where the code isn't *obviously* non-overlapping.
More information about the Libc-alpha
mailing list