Fixed a few things clang's static analysis reported.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 20 Oct 2011 17:50:27 -0400
changeset 1060 4cdf5a3ceb03
parent 1059 9655c606b39d
child 1061 dbf2735676ae
Fixed a few things clang's static analysis reported.
mojoshader.c
mojoshader_compiler.c
mojoshader_opengl.c
mojoshader_preprocessor.c
--- a/mojoshader.c	Thu Oct 20 12:08:12 2011 -0400
+++ b/mojoshader.c	Thu Oct 20 17:50:27 2011 -0400
@@ -541,11 +541,7 @@
         else if (newval < val)  // should have been here if it existed.
             return NULL;
         else // if (newval > val)
-        {
-            // keep going, we're not to the insertion point yet.
-            prev = item;
             item = item->next;
-        } // else
     } // while
 
     return NULL;  // wasn't in the list.
@@ -5740,10 +5736,12 @@
 
                     if (var == NULL)
                         fail(ctx, "relative addressing of indeterminate array");
-
-                    var->used = 1;
-                    info->relative_array = var;
-                    set_used_register(ctx, info->relative_regtype, info->relative_regnum);
+                    else
+                    {
+                        var->used = 1;
+                        info->relative_array = var;
+                        set_used_register(ctx, info->relative_regtype, info->relative_regnum);
+                    } // else
                 } // else
             } // if
         } // else if
@@ -8272,7 +8270,6 @@
     // ...and uniforms...
     for (item = ctx->uniforms.next; item != NULL; item = item->next)
     {
-        int arraybase = -1;
         int arraysize = -1;
 
         // check if this is a register contained in an array...
@@ -8289,7 +8286,6 @@
                 {
                     assert(!var->constant);
                     item->array = var;  // used when building parseData.
-                    arraybase = lo;
                     arraysize = var->count;
                     break;
                 } // if
--- a/mojoshader_compiler.c	Thu Oct 20 12:08:12 2011 -0400
+++ b/mojoshader_compiler.c	Thu Oct 20 17:50:27 2011 -0400
@@ -382,7 +382,7 @@
             if (!buffer_append(ctx->garbage, &userdt, sizeof (userdt)))
             {
                 Free(ctx, userdt);
-                userdt = NULL;
+                return;
             } // if
 
             userdt->type = MOJOSHADER_AST_DATATYPE_USER;
@@ -1888,8 +1888,9 @@
                                         const MOJOSHADER_astDataType **params,
                                         const int intrinsic)
 {
-    assert( ((paramcount == 0) && (params == NULL)) ||
-            ((paramcount > 0) && (params != NULL)) );
+    if ( ((paramcount > 0) && (params == NULL)) ||
+         ((paramcount == 0) && (params != NULL)) )
+        return NULL;
 
     // !!! FIXME: this is hacky.
     const MOJOSHADER_astDataType **dtparams;
@@ -2834,7 +2835,6 @@
             } // if
 
             MOJOSHADER_astArguments *arg = ast->callfunc.args;
-            MOJOSHADER_astArguments *prev = NULL;
             int i;
             for (i = 0; i < reduced->function.num_params; i++)
             {
@@ -2847,7 +2847,6 @@
                 datatype2 = arg->argument->datatype;  // already type-checked.
                 add_type_coercion(ctx, NULL, reduced->function.params[i],
                                   &arg->argument, datatype2);
-                prev = arg;
                 arg = arg->next;
             } // for
 
@@ -5251,13 +5250,10 @@
         if (prev == NULL)
             prev = retval = item;
         else
-        {
             prev->next = item;
-            item = prev;
-        } // else
 
         args = args->next;
-    } // for
+    } // while
 
     return retval;
 } // build_ir_exprlist
--- a/mojoshader_opengl.c	Thu Oct 20 12:08:12 2011 -0400
+++ b/mojoshader_opengl.c	Thu Oct 20 17:50:27 2011 -0400
@@ -1687,16 +1687,11 @@
 
 void MOJOSHADER_glBindProgram(MOJOSHADER_glProgram *program)
 {
-    GLuint handle = 0;
-
     if (program == ctx->bound_program)
         return;  // nothing to do.
 
     if (program != NULL)
-    {
-        handle = program->handle;
         program->refcount++;
-    } // if
 
     memset(ctx->want_attr, '\0', sizeof (ctx->want_attr[0]) * ctx->max_attrs);
 
--- a/mojoshader_preprocessor.c	Thu Oct 20 12:08:12 2011 -0400
+++ b/mojoshader_preprocessor.c	Thu Oct 20 17:50:27 2011 -0400
@@ -1119,8 +1119,11 @@
 handle_pp_define_failed:
     Free(ctx, sym);
     Free(ctx, definition);
-    while (params--)
-        Free(ctx, idents[params]);
+    if (idents != NULL)
+    {
+        while (params--)
+            Free(ctx, idents[params]);
+    } // if
     Free(ctx, idents);
 } // handle_pp_define