From aae28e3ec15b44b285af952075dbc9c1993eb54f Mon Sep 17 00:00:00 2001 From: Steffen Pankratz Date: Mon, 10 Oct 2016 18:28:05 +0200 Subject: [PATCH] Fixed bug 3096 - SDL_BlitSurface with overlapping source and destination --- src/video/SDL_blit_copy.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/video/SDL_blit_copy.c b/src/video/SDL_blit_copy.c index 7b9a91ffd..674650dd9 100644 --- a/src/video/SDL_blit_copy.c +++ b/src/video/SDL_blit_copy.c @@ -109,10 +109,20 @@ SDL_BlitCopy(SDL_BlitInfo * info) overlap = (src < (dst + h*dstskip)); } if (overlap) { - while (h--) { - SDL_memmove(dst, src, w); - src += srcskip; - dst += dstskip; + if ( dst < src ) { + while ( h-- ) { + SDL_memmove(dst, src, w); + src += srcskip; + dst += dstskip; + } + } else { + src += ((h-1) * srcskip); + dst += ((h-1) * dstskip); + while ( h-- ) { + SDL_memmove(dst, src, w); + src -= srcskip; + dst -= dstskip; + } } return; }