[PATCH] gcc_qsort: avoid overlapping memcpy (PR 86311)

Alexander Monakov amonakov@ispras.ru
Mon Jun 25 14:54:00 GMT 2018


On Mon, 25 Jun 2018, Alexander Monakov wrote:
> 
> In PR 86311 Valgrind flags a call to memcpy with overlapping buffers. This can
> happen in reorder{23,45} helpers when we're reordering in-place, and the 3rd/5th
> element doesn't need to be moved: in that case the middle memcpy is called
> with source == destination.
> 
> The fix is simple: just use a temporary, just like for other elements.

Sigh - I see GCC optimizes memmove as well as memcpy in this case, so changing
the offending memcpy calls to memmoves would be a bit cleaner. OK to go with
this instead?

Alexander



More information about the Gcc-patches mailing list