From: José Fonseca Date: Thu, 24 Jul 2014 14:50:56 +0000 (+0100) Subject: st/wgl: Clamp wglChoosePixelFormatARB's output nNumFormats to nMaxFormats. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=66a1b3a1da5cbb75d727c9b4751a06bdd403f0f9;p=mesa.git st/wgl: Clamp wglChoosePixelFormatARB's output nNumFormats to nMaxFormats. While running https://github.com/nvMcJohn/apitest with apitrace I noticed that Mesa was producing bogus results: wglChoosePixelFormatARB(hdc, piAttribIList = {...}, pfAttribFList = &0, nMaxFormats = 1, piFormats = {19, 65576, 37, 198656, 131075, 0, 402653184, 0, 0, 0, 0, -573575710}, nNumFormats = &12) = TRUE However https://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt states returns the number of matching formats. The returned value is guaranteed to be no larger than . Cc: "10.2" Reviewed-by: Brian Paul --- diff --git a/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c b/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c index d303b0153cb..91682d115a4 100644 --- a/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c +++ b/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c @@ -448,9 +448,11 @@ wglChoosePixelFormatARB( */ for (i = 0; i < count; i++) { if (scores[i].points > 0) { - if (*nNumFormats < nMaxFormats) - piFormats[*nNumFormats] = scores[i].index + 1; + piFormats[*nNumFormats] = scores[i].index + 1; (*nNumFormats)++; + if (*nNumFormats >= nMaxFormats) { + break; + } } }