Fix out of bounds access in internal format query tests
authorMika Isojärvi <misojarvi@google.com>
Thu, 10 Mar 2016 22:16:47 +0000 (14:16 -0800)
committerMika Isojärvi <misojarvi@google.com>
Thu, 10 Mar 2016 22:16:47 +0000 (14:16 -0800)
Bug: 27570736
Change-Id: Id95f80765b3ed020515edb544cf871282672d802

modules/gles31/functional/es31fInternalFormatQueryTests.cpp

index 55b6e6a..013f357 100644 (file)
@@ -140,13 +140,11 @@ FormatSamplesCase::IterateResult FormatSamplesCase::iterate (void)
 
        // Sample counts
        {
-               tcu::MessageBuilder             samplesMsg(&m_testCtx.getLog());
-               std::vector<glw::GLint> samples;
+               tcu::MessageBuilder             samplesMsg      (&m_testCtx.getLog());
+               std::vector<glw::GLint> samples         (numSampleCounts > 0 ? numSampleCounts : 1);
 
                if (numSampleCounts > 0 || isFloatFormat)
                {
-                       samples.resize(numSampleCounts, -1);
-
                        gl.getInternalformativ(m_target, m_internalFormat, GL_SAMPLES, numSampleCounts, &samples[0]);
                        GLU_EXPECT_NO_ERROR(gl.getError(), "get GL_SAMPLES");
                }
@@ -156,7 +154,7 @@ FormatSamplesCase::IterateResult FormatSamplesCase::iterate (void)
                // make a pretty log
 
                samplesMsg << "GL_SAMPLES = [";
-               for (int ndx = 0; ndx < numSampleCounts; ++ndx)
+               for (size_t ndx = 0; ndx < samples.size(); ++ndx)
                {
                        if (ndx)
                                samplesMsg << ", ";
@@ -165,7 +163,7 @@ FormatSamplesCase::IterateResult FormatSamplesCase::iterate (void)
                samplesMsg << "]" << tcu::TestLog::EndMessage;
 
                // Samples are in order
-               for (int ndx = 1; ndx < numSampleCounts; ++ndx)
+               for (size_t ndx = 1; ndx < samples.size(); ++ndx)
                {
                        if (samples[ndx-1] <= samples[ndx])
                        {
@@ -176,7 +174,7 @@ FormatSamplesCase::IterateResult FormatSamplesCase::iterate (void)
                }
 
                // samples are positive
-               for (int ndx = 1; ndx < numSampleCounts; ++ndx)
+               for (size_t ndx = 1; ndx < samples.size(); ++ndx)
                {
                        if (samples[ndx-1] <= 0)
                        {