glsl: check number of varying variables against the limit
authorBrian Paul <brianp@vmware.com>
Fri, 8 May 2009 20:32:19 +0000 (14:32 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 8 May 2009 20:35:48 +0000 (14:35 -0600)
Link fails if too many varying vars.

src/mesa/shader/slang/slang_link.c

index 798eb13f20ee4b7ed966b56d5e8a2ea9a4ef8768..2bc8809661d63d8bc846f0b8d7a79b5f2c5415f1 100644 (file)
@@ -97,7 +97,8 @@ bits_agree(GLbitfield flags1, GLbitfield flags2, GLbitfield bit)
  * which inputs are centroid-sampled, invariant, etc.
  */
 static GLboolean
-link_varying_vars(struct gl_shader_program *shProg, struct gl_program *prog)
+link_varying_vars(GLcontext *ctx,
+                  struct gl_shader_program *shProg, struct gl_program *prog)
 {
    GLuint *map, i, firstVarying, newFile;
    GLbitfield *inOutFlags;
@@ -156,8 +157,12 @@ link_varying_vars(struct gl_shader_program *shProg, struct gl_program *prog)
                                var->Flags);
       }
 
+      if (shProg->Varying->NumParameters > ctx->Const.MaxVarying) {
+         link_error(shProg, "Too many varying variables");
+         return GL_FALSE;
+      }
+
       /* Map varying[i] to varying[j].
-       * Plus, set prog->Input/OutputFlags[] as described above.
        * Note: the loop here takes care of arrays or large (sz>4) vars.
        */
       {
@@ -729,11 +734,11 @@ _slang_link(GLcontext *ctx,
 
    /* link varying vars */
    if (shProg->VertexProgram) {
-      if (!link_varying_vars(shProg, &shProg->VertexProgram->Base))
+      if (!link_varying_vars(ctx, shProg, &shProg->VertexProgram->Base))
          return;
    }
    if (shProg->FragmentProgram) {
-      if (!link_varying_vars(shProg, &shProg->FragmentProgram->Base))
+      if (!link_varying_vars(ctx, shProg, &shProg->FragmentProgram->Base))
          return;
    }