Fix signed integer overflow in framebuffer fetch tests
authorAri Suonpaa <ari.suonpaa@siru.fi>
Mon, 23 May 2022 04:53:17 +0000 (07:53 +0300)
committerMatthew Netsch <quic_mnetsch@quicinc.com>
Thu, 16 Jun 2022 20:39:30 +0000 (20:39 +0000)
VK-GL-CTS Issue: 3473

Affects:

dEQP-GLES31.functional.shaders.framebuffer_fetch.framebuffer_format.*

Components: OpenGL ES
Change-Id: I5c971db231c9ea95b413df417e5cb2421aa857e1

modules/gles31/functional/es31fShaderFramebufferFetchTests.cpp

index c8a0d86..6f6c856 100644 (file)
@@ -574,7 +574,13 @@ tcu::TextureLevel TextureFormatTestCase::genReferenceTexture (const tcu::Vec4& f
        }
        else if (textureChannelClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
        {
-               tcu::clear(reference.getAccess(), fbColor.asInt() + uniformColor.asInt());
+               tcu::IVec4 clearColor;
+
+               // Calculate using 64 bits to avoid signed integer overflow.
+               for (int i = 0; i < 4; i++)
+                       clearColor[i] = static_cast<int>((static_cast<deInt64>(fbColor.asInt()[i]) + static_cast<deInt64>(uniformColor.asInt()[i])) & 0xffffffff);
+
+               tcu::clear(reference.getAccess(), clearColor);
        }
        else
        {