From 138bf5ac9703b410a6066c303feea067680edf5a Mon Sep 17 00:00:00 2001 From: Jamey Sharp Date: Fri, 18 Apr 2014 12:22:19 -0700 Subject: [PATCH] DRI2SwapBuffers: Fix uninitialized target SBC. Fixes Piglit test "swapbuffersmsc-return swap_interval 0". Ensure that *swap_target gets initialized on any 'return Success' path, even if the swap request can't be completed by the driver and the server falls back to a simple blit. That path can also be triggered by setting swap_interval to 0, which disables sync to vertical retrace. We originally found this bug because for some reason SDL2 automatically sets swap_interval to 0, when we were trying to test OML_sync_control in an SDL2 test application. We then discovered that the above-mentioned Piglit test has been failing for the same reason since it was introduced. Signed-off-by: Jamey Sharp Signed-off-by: Theo Hill Reviewed-by: Keith Packard Reviewed-by: Eric Anholt Signed-off-by: Keith Packard --- hw/xfree86/dri2/dri2.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c index 962f40cc9..76708cabc 100644 --- a/hw/xfree86/dri2/dri2.c +++ b/hw/xfree86/dri2/dri2.c @@ -1092,6 +1092,14 @@ DRI2SwapBuffers(ClientPtr client, DrawablePtr pDraw, CARD64 target_msc, return BadDrawable; } + /* According to spec, return expected swapbuffers count SBC after this swap + * will complete. This is ignored unless we return Success, but it must be + * initialized on every path where we return Success or the caller will send + * an uninitialized value off the stack to the client. So let's initialize + * it as early as possible, just to be sure. + */ + *swap_target = pPriv->swap_count + pPriv->swapsPending + 1; + for (i = 0; i < pPriv->bufferCount; i++) { if (pPriv->buffers[i]->attachment == DRI2BufferFrontLeft) pDestBuffer = (DRI2BufferPtr) pPriv->buffers[i]; @@ -1165,11 +1173,6 @@ DRI2SwapBuffers(ClientPtr client, DrawablePtr pDraw, CARD64 target_msc, pPriv->last_swap_target = target_msc; - /* According to spec, return expected swapbuffers count SBC after this swap - * will complete. - */ - *swap_target = pPriv->swap_count + pPriv->swapsPending; - DRI2InvalidateDrawableAll(pDraw); return Success;