diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-01-03 15:16:29 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-03 20:55:20 +0000 |
commit | 9a5610e35d1a54161c1d4b15bd49145fd5ab49ca (patch) | |
tree | 3ad32558f25e2a7ee5b8e11868b7c7e9d17cb4af /src/sksl | |
parent | 87f340e52a1af24766659c63035331e8b0b6355f (diff) |
fixed a divide-by-zero bug in skslc
BUG=skia:5960
Change-Id: I8ace6efefd14b11c3bc2448a1ab4e3353a29075f
Reviewed-on: https://skia-review.googlesource.com/6539
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl')
-rw-r--r-- | src/sksl/SkSLIRGenerator.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 06988173aa..0f035af32e 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -876,7 +876,12 @@ std::unique_ptr<Expression> IRGenerator::constantFold(const Expression& left, case Token::PLUS: return RESULT(Int, +); case Token::MINUS: return RESULT(Int, -); case Token::STAR: return RESULT(Int, *); - case Token::SLASH: return RESULT(Int, /); + case Token::SLASH: + if (rightVal) { + return RESULT(Int, /); + } + fErrors.error(right.fPosition, "division by zero"); + return nullptr; case Token::PERCENT: return RESULT(Int, %); case Token::BITWISEAND: return RESULT(Int, &); case Token::BITWISEOR: return RESULT(Int, |); @@ -900,7 +905,12 @@ std::unique_ptr<Expression> IRGenerator::constantFold(const Expression& left, case Token::PLUS: return RESULT(Float, +); case Token::MINUS: return RESULT(Float, -); case Token::STAR: return RESULT(Float, *); - case Token::SLASH: return RESULT(Float, /); + case Token::SLASH: + if (rightVal) { + return RESULT(Float, /); + } + fErrors.error(right.fPosition, "division by zero"); + return nullptr; case Token::EQEQ: return RESULT(Bool, ==); case Token::NEQ: return RESULT(Bool, !=); case Token::GT: return RESULT(Bool, >); |