[Piglit] [PATCH 1/4] texunits: increase size of arrays to fix crash

Brian Paul brianp at vmware.com
Mon Mar 18 17:19:05 PDT 2013


NVIDIA's later GPUs/drivers report 192 combined texture units.
This causes us to read outside the too-small arrays and segfault.

Increase the array sizes and add a check for the future.
---
 tests/general/texunits.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/tests/general/texunits.c b/tests/general/texunits.c
index 3140f80..e419bde 100644
--- a/tests/general/texunits.c
+++ b/tests/general/texunits.c
@@ -40,8 +40,10 @@ PIGLIT_GL_TEST_CONFIG_BEGIN
 
 PIGLIT_GL_TEST_CONFIG_END
 
+#define MAX_UNITS 256
+
 /** random number for checking state */
-static GLfloat Random[128][4];
+static GLfloat Random[MAX_UNITS][4];
 
 static GLint MaxTextureCoordUnits;
 static GLint MaxTextureVertexUnits;
@@ -53,7 +55,7 @@ static void
 generate_random_numbers(void)
 {
    int i, j;
-   for (i = 0; i < 128; i++) {
+   for (i = 0; i < ARRAY_SIZE(Random); i++) {
       for (j = 0; j < 4; j++) {
          /* values in [0, 1] */
          Random[i][j] = (rand() % 1000) * .001;
@@ -233,7 +235,7 @@ test_texture_matrix(void)
 static GLboolean
 test_texture_params(void)
 {
-   GLuint tex[100];
+   GLuint tex[MAX_UNITS];
    GLenum err;
    int i;
    int maxUnit;
@@ -376,6 +378,11 @@ init(void)
 
    report_info();
 
+   if (MaxTextureCombinedUnits > MAX_UNITS) {
+      /* Need to increase the MAX_UNITS limit */
+      piglit_report_result(PIGLIT_WARN);
+   }
+
    generate_random_numbers();
 
    glMatrixMode(GL_PROJECTION);
-- 
1.7.3.4



More information about the Piglit mailing list