Make sure swizzle isn't too large ("float2(1,2).xyz" is invalid).
authorRyan C. Gordon <icculus@icculus.org>
Tue, 18 Jan 2011 00:32:15 -0500
changeset 980 83e96d285449
parent 979 f3d1c6675d97
child 981 bfcdebd39e5b
Make sure swizzle isn't too large ("float2(1,2).xyz" is invalid).
mojoshader_compiler.c
--- a/mojoshader_compiler.c	Tue Jan 18 00:29:14 2011 -0500
+++ b/mojoshader_compiler.c	Tue Jan 18 00:32:15 2011 -0500
@@ -2148,7 +2148,7 @@
     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;
@@ -2156,7 +2156,7 @@
 
     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')
@@ -2310,8 +2310,9 @@
             // 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.
@@ -2320,7 +2321,7 @@
                 } // if
 
                 const int swizlen = (int) strlen(member);
-                if (swizlen == reduced->vector.elements)
+                if (swizlen == veclen)
                     datatype = reduced;
                 else
                 {