From 9a5610e35d1a54161c1d4b15bd49145fd5ab49ca Mon Sep 17 00:00:00 2001 From: Ethan Nicholas Date: Tue, 3 Jan 2017 15:16:29 -0500 Subject: 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 Commit-Queue: Ethan Nicholas --- src/sksl/SkSLIRGenerator.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/sksl') 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 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 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, >); -- cgit v1.2.3