From 0966f536b8c6ec79dc2ae44f4139cf765bf49f18 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 13 Apr 2019 18:18:48 +0300 Subject: [PATCH] Fixed issue #964. Assign operator crashes math parser. (grafted from 9fd845b77249b4edc1bdc0a42dc4b32fb5f036f6) --HG-- branch : develop --- ChangeLog.txt | 1 + src/libs/qmuparser/qmuparserbase.cpp | 8 ++++++-- src/libs/qmuparser/qmuparsertest.cpp | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index f659047da..1917fdb58 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -36,6 +36,7 @@ - [#957] Unable to cut an arc with negative length. - [#962] Failed to load LibEGL. - [#963] Bug in tool Point intersect curve and axis. +- [#964] Assign operator crashes math parser. # Version 0.6.1 October 23, 2018 - [#885] Regression. Broken support for multi size measurements. diff --git a/src/libs/qmuparser/qmuparserbase.cpp b/src/libs/qmuparser/qmuparserbase.cpp index 131f7ea76..965db60e9 100644 --- a/src/libs/qmuparser/qmuparserbase.cpp +++ b/src/libs/qmuparser/qmuparserbase.cpp @@ -915,7 +915,11 @@ void QmuParserBase::ApplyBinOprt(QStack &a_stOpt, QStack } else { - Q_ASSERT(a_stVal.size()>=2); + if(a_stVal.size()<2) + { + Error(ecUNEXPECTED_OPERATOR); + } + token_type valTok1 = a_stVal.pop(), valTok2 = a_stVal.pop(), optTok = a_stOpt.pop(), @@ -930,7 +934,7 @@ void QmuParserBase::ApplyBinOprt(QStack &a_stOpt, QStack { if (valTok2.GetCode()!=cmVAR) { - Error(ecUNEXPECTED_OPERATOR, -1, "="); + Error(ecUNEXPECTED_OPERATOR, -1, QChar('=')); } m_vRPN.AddAssignOp(valTok2.GetVar()); } diff --git a/src/libs/qmuparser/qmuparsertest.cpp b/src/libs/qmuparser/qmuparsertest.cpp index 9778616b3..fd22a71c9 100644 --- a/src/libs/qmuparser/qmuparsertest.cpp +++ b/src/libs/qmuparser/qmuparsertest.cpp @@ -266,6 +266,7 @@ int QmuParserTester::TestBinOprt() iStat += EqnTest ( "2*(a=b+1)", 6, true ); iStat += EqnTest ( "(a=b+1)*2", 6, true ); iStat += EqnTest ( "a=c; a*10", 30, true); + iStat += EqnTest ( "a = -", 0, false ); // broken assigment iStat += EqnTest ( "2^2^3", 256, true ); iStat += EqnTest ( "1/2/3", 1.0 / 6.0, true );