Commit d1d1dff6 by Olli Etuaho Committed by Commit Bot

Fix undefined modulus in ExpressionParser

In constant folding of integer expressions this case is already being handled. BUG=angleproject:1599 Change-Id: Ifb3ea0279467f216e1c93909647b79fca24fcaf2 Reviewed-on: https://chromium-review.googlesource.com/406868 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent e7dc9d71
...@@ -500,7 +500,7 @@ static const yytype_uint16 yyrline[] = ...@@ -500,7 +500,7 @@ static const yytype_uint16 yyrline[] =
{ {
0, 108, 108, 115, 116, 127, 127, 148, 148, 169, 0, 108, 108, 115, 116, 127, 127, 148, 148, 169,
172, 175, 178, 181, 184, 187, 190, 193, 196, 221, 172, 175, 178, 181, 184, 187, 190, 193, 196, 221,
246, 249, 252, 272, 299, 302, 305, 308, 320, 323 246, 249, 252, 278, 305, 308, 311, 314, 326, 329
}; };
#endif #endif
...@@ -1583,6 +1583,12 @@ yyreduce: ...@@ -1583,6 +1583,12 @@ yyreduce:
} }
(yyval) = static_cast<YYSTYPE>(0); (yyval) = static_cast<YYSTYPE>(0);
} }
else if (((yyvsp[-2]) == std::numeric_limits<YYSTYPE>::min()) && ((yyvsp[0]) == -1))
{
// Check for the special case where the minimum representable number is
// divided by -1. If left alone this has undefined results.
(yyval) = 0;
}
else else
{ {
(yyval) = (yyvsp[-2]) % (yyvsp[0]); (yyval) = (yyvsp[-2]) % (yyvsp[0]);
...@@ -1608,7 +1614,7 @@ yyreduce: ...@@ -1608,7 +1614,7 @@ yyreduce:
} }
(yyval) = static_cast<YYSTYPE>(0); (yyval) = static_cast<YYSTYPE>(0);
} }
else if ((yyvsp[-2]) == std::numeric_limits<YYSTYPE>::min() && (yyvsp[0]) == -1) else if (((yyvsp[-2]) == std::numeric_limits<YYSTYPE>::min()) && ((yyvsp[0]) == -1))
{ {
// Check for the special case where the minimum representable number is // Check for the special case where the minimum representable number is
// divided by -1. If left alone this leads to integer overflow in C++, which // divided by -1. If left alone this leads to integer overflow in C++, which
......
...@@ -264,6 +264,12 @@ expression ...@@ -264,6 +264,12 @@ expression
} }
$$ = static_cast<YYSTYPE>(0); $$ = static_cast<YYSTYPE>(0);
} }
else if (($1 == std::numeric_limits<YYSTYPE>::min()) && ($3 == -1))
{
// Check for the special case where the minimum representable number is
// divided by -1. If left alone this has undefined results.
$$ = 0;
}
else else
{ {
$$ = $1 % $3; $$ = $1 % $3;
...@@ -284,7 +290,7 @@ expression ...@@ -284,7 +290,7 @@ expression
} }
$$ = static_cast<YYSTYPE>(0); $$ = static_cast<YYSTYPE>(0);
} }
else if ($1 == std::numeric_limits<YYSTYPE>::min() && $3 == -1) else if (($1 == std::numeric_limits<YYSTYPE>::min()) && ($3 == -1))
{ {
// Check for the special case where the minimum representable number is // Check for the special case where the minimum representable number is
// divided by -1. If left alone this leads to integer overflow in C++, which // divided by -1. If left alone this leads to integer overflow in C++, which
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment