OSDN Git Service

Initialize array size on error.
authorNicolas Capens <capn@google.com>
Mon, 9 Apr 2018 15:53:41 +0000 (11:53 -0400)
committerNicolas Capens <nicolascapens@google.com>
Mon, 9 Apr 2018 16:50:18 +0000 (16:50 +0000)
The array size is set using the value returned by arraySizeErrorCheck,
even when an error occurred, so don't leave it uninitialized.

Bug chromium:801648

Change-Id: If2af27c5f61dca2931796f1681dce61ab6a44341
Reviewed-on: https://swiftshader-review.googlesource.com/18368
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
src/OpenGL/compiler/ParseHelper.cpp
src/OpenGL/compiler/glslang.y
src/OpenGL/compiler/glslang_tab.cpp

index c7100ba..6d4b149 100644 (file)
@@ -802,6 +802,7 @@ bool TParseContext::arraySizeErrorCheck(const TSourceLoc &line, TIntermTyped* ex
        if (expr->getQualifier() != EvqConstExpr || constant == 0 || !constant->isScalarInt())
        {
                error(line, "array size must be a constant integer expression", "");
+               size = 1;
                return true;
        }
 
@@ -1485,7 +1486,7 @@ TIntermAggregate *TParseContext::parseSingleArrayDeclaration(TPublicType &public
 
        TType arrayType(publicType);
 
-       int size;
+       int size = 0;
        if(arraySizeErrorCheck(identifierLocation, indexExpression, size))
        {
                recover();
@@ -1666,7 +1667,7 @@ TIntermAggregate *TParseContext::parseArrayDeclarator(TPublicType &publicType, T
        else
        {
                TType arrayType = TType(publicType);
-               int size;
+               int size = 0;
                if(arraySizeErrorCheck(arrayLocation, indexExpression, size))
                {
                        recover();
index cd0daff..f970d3b 100644 (file)
@@ -728,7 +728,7 @@ parameter_declarator
         if (context->reservedErrorCheck(@2, *$2.string))
             context->recover();
 
-        int size;
+        int size = 0;
         if (context->arraySizeErrorCheck(@3, $4, size))
             context->recover();
         $1.setArray(true, size);
@@ -1069,7 +1069,7 @@ type_specifier_no_prec
         if (context->arrayTypeErrorCheck(@2, $1))
             context->recover();
         else {
-            int size;
+            int size = 0;
             if (context->arraySizeErrorCheck(@2, $3, size))
                 context->recover();
             $$.setArray(true, size);
@@ -1385,7 +1385,7 @@ struct_declarator
             context->recover();
 
         TType* type = new TType(EbtVoid, EbpUndefined);
-        int size;
+        int size = 0;
         if (context->arraySizeErrorCheck($3->getLine(), $3, size))
             context->recover();
         type->setArraySize(size);
index 811da14..45d73fe 100644 (file)
@@ -3249,7 +3249,7 @@ yyreduce:
         if (context->reservedErrorCheck((yylsp[-3]), *(yyvsp[-3].lex).string))
             context->recover();
 
-        int size;
+        int size = 0;
         if (context->arraySizeErrorCheck((yylsp[-2]), (yyvsp[-1].interm.intermTypedNode), size))
             context->recover();
         (yyvsp[-4].interm.type).setArray(true, size);
@@ -3816,7 +3816,7 @@ yyreduce:
         if (context->arrayTypeErrorCheck((yylsp[-2]), (yyvsp[-3].interm.type)))
             context->recover();
         else {
-            int size;
+            int size = 0;
             if (context->arraySizeErrorCheck((yylsp[-2]), (yyvsp[-1].interm.intermTypedNode), size))
                 context->recover();
             (yyval.interm.type).setArray(true, size);
@@ -4401,7 +4401,7 @@ yyreduce:
             context->recover();
 
         TType* type = new TType(EbtVoid, EbpUndefined);
-        int size;
+        int size = 0;
         if (context->arraySizeErrorCheck((yyvsp[-1].interm.intermTypedNode)->getLine(), (yyvsp[-1].interm.intermTypedNode), size))
             context->recover();
         type->setArraySize(size);