Skip to content

Commit

Permalink
Make sure swizzle isn't too large ("float2(1,2).xyz" is invalid).
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jan 18, 2011
1 parent 8873108 commit 522f69c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mojoshader_compiler.c
Expand Up @@ -2148,15 +2148,15 @@ static const MOJOSHADER_astDataType *add_type_coercion(Context *ctx,
return ldatatype;
} // add_type_coercion

static int is_swizzle_str(const char *str)
static int is_swizzle_str(const char *str, const int veclen)
{
int i;
int is_xyzw = 0;
int is_rgba = 0;

assert(*str != '\0'); // can this actually happen?

for (i = 0; i < 4; i++, str++)
for (i = 0; i < veclen; i++, str++)
{
const char ch = *str;
if (ch == '\0')
Expand Down Expand Up @@ -2310,8 +2310,9 @@ static const MOJOSHADER_astDataType *type_check_ast(Context *ctx, void *_ast)
// Is this a swizzle and not a struct deref?
if (reduced->type == MOJOSHADER_AST_DATATYPE_VECTOR)
{
const int veclen = reduced->vector.elements;
ast->derefstruct.isswizzle = 1;
if (!is_swizzle_str(member))
if (!is_swizzle_str(member, veclen))
{
fail(ctx, "invalid swizzle on vector");
// force this to be sane for further processing.
Expand All @@ -2320,7 +2321,7 @@ static const MOJOSHADER_astDataType *type_check_ast(Context *ctx, void *_ast)
} // if

const int swizlen = (int) strlen(member);
if (swizlen == reduced->vector.elements)
if (swizlen == veclen)
datatype = reduced;
else
{
Expand Down

0 comments on commit 522f69c

Please sign in to comment.