From dd8c2b5e82482e3aad1f3ea4c6493d0e2e80b7c7 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 20 Oct 2011 17:50:27 -0400 Subject: [PATCH] Fixed a few things clang's static analysis reported. --- mojoshader.c | 16 ++++++---------- mojoshader_compiler.c | 14 +++++--------- mojoshader_opengl.c | 5 ----- mojoshader_preprocessor.c | 7 +++++-- 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index 34abd8d6..f8f25180 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -541,11 +541,7 @@ static RegisterList *reglist_find(const RegisterList *prev, 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 @@ static int parse_source_token(Context *ctx, SourceArgInfo *info) 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 @@ static void process_definitions(Context *ctx) // ...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 @@ static void process_definitions(Context *ctx) { assert(!var->constant); item->array = var; // used when building parseData. - arraybase = lo; arraysize = var->count; break; } // if diff --git a/mojoshader_compiler.c b/mojoshader_compiler.c index ab6b53aa..6f6e11c2 100644 --- a/mojoshader_compiler.c +++ b/mojoshader_compiler.c @@ -382,7 +382,7 @@ static void push_usertype(Context *ctx, const char *sym, const MOJOSHADER_astDat 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 @@ static const MOJOSHADER_astDataType *build_function_datatype(Context *ctx, 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 @@ static const MOJOSHADER_astDataType *type_check_ast(Context *ctx, void *_ast) } // 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 @@ static const MOJOSHADER_astDataType *type_check_ast(Context *ctx, void *_ast) 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 @@ static MOJOSHADER_irExprList *build_ir_exprlist(Context *ctx, MOJOSHADER_astArgu if (prev == NULL) prev = retval = item; else - { prev->next = item; - item = prev; - } // else args = args->next; - } // for + } // while return retval; } // build_ir_exprlist diff --git a/mojoshader_opengl.c b/mojoshader_opengl.c index 50365679..05363123 100644 --- a/mojoshader_opengl.c +++ b/mojoshader_opengl.c @@ -1687,16 +1687,11 @@ static void update_enabled_arrays(void) 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); diff --git a/mojoshader_preprocessor.c b/mojoshader_preprocessor.c index ad0bd52c..233566ae 100644 --- a/mojoshader_preprocessor.c +++ b/mojoshader_preprocessor.c @@ -1119,8 +1119,11 @@ static void handle_pp_define(Context *ctx) 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