fbBlt - memcpy on overlapping ranges

Mihai Donțu mihai.dontu at gmail.com
Thu May 24 08:38:22 PDT 2012


On Thu, 24 May 2012 17:20:16 +0200 Michal Srb wrote:
> Hi,
> 
> In fb/fbblt.c in fbBlt function, memcpy is used to blit inside lines:
> 
> if (!upsidedown)
>      for (i = 0; i < height; i++)
>          MEMCPY_WRAPPED(dst + i * dstStride, src + i * srcStride,
> width); else
>      for (i = height - 1; i >= 0; i--)
>          MEMCPY_WRAPPED(dst + i * dstStride, src + i * srcStride,
> width);
> 
> 
> Where MEMCPY_WRAPPED is normaly expanded to standard memcpy function.
> 
> In case of blitting in horizontal direction of less than width
> overlapping will occur. According to memcpy documentation, result is
> undefined in such case. Shouldn't memmove be used instead?
> 
> (This does happen, found using clang's AddressSanitizer - steps I
> used: run X without any client in vmware, then kate and then kwin.)
> 

If an overlap does happen, then one should use memmove(), at least as
far as GNU libc is concerned[1].

[1] http://lwn.net/Articles/414467/

-- 
Mihai Donțu


More information about the xorg-devel mailing list