Skip to content

Commit

Permalink
Fixed a few things clang's static analysis reported.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Oct 20, 2011
1 parent 5929b22 commit dd8c2b5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
16 changes: 6 additions & 10 deletions mojoshader.c
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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...
Expand All @@ -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
Expand Down
14 changes: 5 additions & 9 deletions mojoshader_compiler.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++)
{
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions mojoshader_opengl.c
Expand Up @@ -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);

Expand Down
7 changes: 5 additions & 2 deletions mojoshader_preprocessor.c
Expand Up @@ -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

Expand Down

0 comments on commit dd8c2b5

Please sign in to comment.