Reorder some code so we don't upset program state when there's a parsing error.
authorBrian Paul <brian.paul@tungstengraphics.com>
Tue, 30 Mar 2004 15:55:10 +0000 (15:55 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Tue, 30 Mar 2004 15:55:10 +0000 (15:55 +0000)
Be sure to assign program.Base.String pointer.

src/mesa/shader/arbfragparse.c
src/mesa/shader/arbprogparse.c
src/mesa/shader/arbvertparse.c

index d876946..7192156 100644 (file)
@@ -192,9 +192,19 @@ _mesa_parse_arb_fragment_program(GLcontext * ctx, GLenum target,
 
    retval = _mesa_parse_arb_program(ctx, str, len, &ap);
 
+   /* XXX: Parse error. Cleanup things and return */
+   if (retval)
+   {
+      program->Instructions = (struct fp_instruction *) _mesa_malloc (
+                                     sizeof(struct fp_instruction) );
+      program->Instructions[0].Opcode = FP_OPCODE_END;
+      return;
+   }
+
    /* copy the relvant contents of the arb_program struct into the
     * fragment_program struct
     */
+   program->Base.String          = ap.Base.String;
    program->Base.NumInstructions = ap.Base.NumInstructions;
    program->Base.NumTemporaries  = ap.Base.NumTemporaries;
    program->Base.NumParameters   = ap.Base.NumParameters;
@@ -211,15 +221,6 @@ _mesa_parse_arb_fragment_program(GLcontext * ctx, GLenum target,
    program->Parameters         = ap.Parameters;
    program->FogOption          = ap.FogOption;
 
-   /* XXX: Parse error. Cleanup things and return */
-   if (retval)
-   {
-      program->Instructions = (struct fp_instruction *) _mesa_malloc (
-                                     sizeof(struct fp_instruction) );
-      program->Instructions[0].Opcode = FP_OPCODE_END;
-      return;
-   }
-
    /* XXX: Eh.. we parsed something that wasn't a fragment program. doh! */
    /* this wont happen any more */
 /*
index c2365a2..9099fd8 100644 (file)
@@ -3872,11 +3872,9 @@ _mesa_parse_arb_program (GLcontext * ctx, const GLubyte * str, GLsizei len,
 #endif
    err = grammar_check (arbprogram_syn_id, strz, &parsed, &parsed_len);
 
-   _mesa_free (strz);
-   strz = NULL;
-
    /* Syntax parse error */
    if (err == 0) {
+      _mesa_free (strz);
       grammar_get_last_error ((GLubyte *) error_msg, 300, &error_pos);
       _mesa_set_program_error (ctx, error_pos, error_msg);
       _mesa_error (ctx, GL_INVALID_OPERATION, "Parse Error");
@@ -3891,6 +3889,7 @@ _mesa_parse_arb_program (GLcontext * ctx, const GLubyte * str, GLsizei len,
    grammar_destroy (arbprogram_syn_id);
 
    /* Initialize the arb_program struct */
+   program->Base.String = strz;
    program->Base.NumInstructions =
    program->Base.NumTemporaries =
    program->Base.NumParameters =
index 5f01110..cfad87b 100644 (file)
@@ -181,9 +181,19 @@ _mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target,
 
    retval = _mesa_parse_arb_program(ctx, str, len, &ap);
 
+   /*  Parse error. Allocate a dummy program and return */     
+   if (retval)
+   {
+      program->Instructions = (struct vp_instruction *) _mesa_malloc (
+                                     sizeof(struct vp_instruction) );                    
+      program->Instructions[0].Opcode = VP_OPCODE_END;
+      return;
+   }
+
    /* copy the relvant contents of the arb_program struct into the 
     * fragment_program struct
     */
+   program->Base.String          = ap.Base.String;
    program->Base.NumInstructions = ap.Base.NumInstructions;
    program->Base.NumTemporaries  = ap.Base.NumTemporaries;
    program->Base.NumParameters   = ap.Base.NumParameters;
@@ -195,15 +205,6 @@ _mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target,
    program->OutputsWritten = ap.OutputsWritten;
    program->Parameters     = ap.Parameters; 
 
-   /*  Parse error. Allocate a dummy program and return */     
-   if (retval)
-   {
-      program->Instructions = (struct vp_instruction *) _mesa_malloc (
-                                     sizeof(struct vp_instruction) );                    
-      program->Instructions[0].Opcode = VP_OPCODE_END;
-      return;
-   }
-
    /* Eh.. we parsed something that wasn't a vertex program. doh! */
    /* this wont happen any more */
 /*