Some static analysis fixes from Clang 4.0.
--- a/misc/lemon.c Thu Jun 07 04:31:01 2012 -0400
+++ b/misc/lemon.c Fri Aug 03 13:39:36 2012 -0400
@@ -2821,7 +2821,7 @@
*/
if(( *mode=='w' ) && (strcmp(suffix, ".out") != 0)){
const char **ptr = (const char **)
- realloc(made_files, sizeof (const char **) * (made_files_count + 1));
+ realloc(made_files, sizeof (const char *) * (made_files_count + 1));
const char *fname = Strsafe(lemp->outname);
if ((ptr == NULL) || (fname == NULL)) {
free(ptr);
@@ -3460,7 +3460,7 @@
int *plineno, /* Pointer to the line number */
int mhflag /* True if generating makeheaders output */
){
- int lineno = *plineno; /* The line number of the output */
+ int lineno = 0; /* The line number of the output */
char **types; /* A hash table of datatypes */
int arraysize; /* Size of the "types" array */
int maxdtlength; /* Maximum length of any ".datatype" field. */
--- a/mojoshader.c Thu Jun 07 04:31:01 2012 -0400
+++ b/mojoshader.c Fri Aug 03 13:39:36 2012 -0400
@@ -7008,11 +7008,14 @@
else
{
ConstantsList *item = alloc_constant_listitem(ctx);
- item->constant.index = regnum;
- item->constant.type = MOJOSHADER_UNIFORM_FLOAT;
- memcpy(item->constant.value.f, ctx->dwords,
- sizeof (item->constant.value.f));
- set_defined_register(ctx, regtype, regnum);
+ if (item != NULL)
+ {
+ item->constant.index = regnum;
+ item->constant.type = MOJOSHADER_UNIFORM_FLOAT;
+ memcpy(item->constant.value.f, ctx->dwords,
+ sizeof (item->constant.value.f));
+ set_defined_register(ctx, regtype, regnum);
+ } // if
} // else
} // state_DEF
@@ -7030,12 +7033,15 @@
else
{
ConstantsList *item = alloc_constant_listitem(ctx);
- item->constant.index = regnum;
- item->constant.type = MOJOSHADER_UNIFORM_INT;
- memcpy(item->constant.value.i, ctx->dwords,
- sizeof (item->constant.value.i));
-
- set_defined_register(ctx, regtype, regnum);
+ if (item != NULL)
+ {
+ item->constant.index = regnum;
+ item->constant.type = MOJOSHADER_UNIFORM_INT;
+ memcpy(item->constant.value.i, ctx->dwords,
+ sizeof (item->constant.value.i));
+
+ set_defined_register(ctx, regtype, regnum);
+ } // if
} // else
} // state_DEFI
@@ -7053,10 +7059,13 @@
else
{
ConstantsList *item = alloc_constant_listitem(ctx);
- item->constant.index = regnum;
- item->constant.type = MOJOSHADER_UNIFORM_BOOL;
- item->constant.value.b = ctx->dwords[0] ? 1 : 0;
- set_defined_register(ctx, regtype, regnum);
+ if (item != NULL)
+ {
+ item->constant.index = regnum;
+ item->constant.type = MOJOSHADER_UNIFORM_BOOL;
+ item->constant.value.b = ctx->dwords[0] ? 1 : 0;
+ set_defined_register(ctx, regtype, regnum);
+ } // if
} // else
} // state_DEFB
--- a/mojoshader_common.c Thu Jun 07 04:31:01 2012 -0400
+++ b/mojoshader_common.c Fri Aug 03 13:39:36 2012 -0400
@@ -259,7 +259,8 @@
HashTable_NukeFn nuke = copy ? stringmap_nuke : stringmap_nuke_noop;
StringMap *smap;
smap = hash_create(0,hash_hash_string,hash_keymatch_string,nuke,0,m,f,d);
- smap->data = smap;
+ if (smap != NULL)
+ smap->data = smap;
return smap;
} // stringmap_create
--- a/mojoshader_compiler.c Thu Jun 07 04:31:01 2012 -0400
+++ b/mojoshader_compiler.c Fri Aug 03 13:39:36 2012 -0400
@@ -2325,6 +2325,9 @@
static const MOJOSHADER_astDataType *datatype_base(Context *ctx, const MOJOSHADER_astDataType *dt)
{
dt = reduce_datatype(ctx, dt);
+ if (dt == NULL)
+ return dt;
+
switch (dt->type)
{
case MOJOSHADER_AST_DATATYPE_VECTOR:
@@ -4600,6 +4603,7 @@
MOJOSHADER_irExpression *left,
MOJOSHADER_irExpression *right)
{
+ if ((!left) || (!right)) return NULL;
NEW_IR_EXPR(retval, MOJOSHADER_irBinOp, MOJOSHADER_IR_BINOP, left->info.type, left->info.elements);
assert(left->info.type == right->info.type);
assert(left->info.elements == right->info.elements);
@@ -4613,6 +4617,7 @@
MOJOSHADER_irStatement *stmt,
MOJOSHADER_irExpression *expr)
{
+ if (!expr) return NULL;
NEW_IR_EXPR(retval, MOJOSHADER_irESeq, MOJOSHADER_IR_ESEQ, expr->info.type, expr->info.elements);
retval->stmt = stmt;
retval->expr = expr;
@@ -4779,8 +4784,8 @@
const int writemask)
{
NEW_IR_NODE(retval, MOJOSHADER_irMove, MOJOSHADER_IR_MOVE);
- assert(dst->info.type == src->info.type);
- assert(dst->info.elements == src->info.elements);
+ assert(dst && src && (dst->info.type == src->info.type));
+ assert(dst && src && (dst->info.elements == src->info.elements));
retval->dst = dst;
retval->src = src;
retval->writemask = writemask;
@@ -4832,8 +4837,8 @@
const int join = generate_ir_label(ctx);
const int tmp = generate_ir_temp(ctx);
- assert(tval->info.type == fval->info.type);
- assert(tval->info.elements == fval->info.elements);
+ assert(tval && fval && (tval->info.type == fval->info.type));
+ assert(tval && fval && (tval->info.elements == fval->info.elements));
const MOJOSHADER_astDataTypeType dt = tval->info.type;
const int elements = tval->info.elements;
@@ -5320,6 +5325,9 @@
MOJOSHADER_irExpression *expr = build_ir_expr(ctx, ast->identifier);
MOJOSHADER_irExpression *finalexpr = expr;
+ if (expr == NULL)
+ return NULL;
+
assert(!ast->isswizzle);
while (finalexpr->ir.type == MOJOSHADER_IR_ESEQ)
--- a/mojoshader_opengl.c Thu Jun 07 04:31:01 2012 -0400
+++ b/mojoshader_opengl.c Fri Aug 03 13:39:36 2012 -0400
@@ -2453,7 +2453,8 @@
// !!! FIXME: set constants that overlap the array.
} // for
- if (program->texbem_count)
+ assert((!program->texbem_count) || (program->fragment));
+ if ((program->texbem_count) && (program->fragment))
{
const MOJOSHADER_parseData *pd = program->fragment->parseData;
const int samp_count = pd->sampler_count;
@@ -2481,7 +2482,7 @@
} // for
assert(texbem_count == program->texbem_count);
- } // for
+ } // if
program->generation = ctx->generation;