[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdeedu/kalgebra/analitza
From: Aleix Pol Gonzalez <aleixpol () gmail ! com>
Date: 2009-01-31 21:46:31
Message-ID: 1233438391.746341.2540.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 919405 by apol:
Do not crash when a wrong number of parameters is simplified or a wrong parametered \
selector is calculated.
M +12 -3 analitza.cpp
M +18 -1 container.cpp
M +2 -0 container.h
M +5 -3 tests/analitzatest.cpp
--- trunk/KDE/kdeedu/kalgebra/analitza/analitza.cpp #919404:919405
@@ -634,6 +634,10 @@
else if(opt==Operator::product)
ret = product(*c);
else if(opt==Operator::selector) {
+ if(KDE_ISUNLIKELY(c->m_params.size()!=3)) {
+ m_err += i18n("Wrong parameter count in a selector, should have 2 parameters, \
the selected index and the container."); + return new Cn(0.);
+ }
Object *idx=calc(c->m_params[1]), *vect=calc(c->m_params[2]);
ret = selector(idx, vect);
delete idx; delete vect;
@@ -907,7 +911,13 @@
} else if(c->containerType()==Container::apply) {
Container::iterator it;
Operator o = c->firstOperator();
- switch(o.operatorType()) {
+
+ if(KDE_ISUNLIKELY(!c->isCorrect())) {
+ it = c->firstValue();
+
+ for(; it!=c->m_params.end(); ++it)
+ *it = simp(*it);
+ } else switch(o.operatorType()) {
case Operator::times:
for(it=c->firstValue(); c->m_params.count()>1 && it!=c->m_params.end();) {
d=false;
@@ -1165,8 +1175,7 @@
Object* idx=c->m_params[1];
Object* value=c->m_params[2];
- if(idx->type()==Object::value && value->type()==Object::vector)
- {
+ if(idx->type()==Object::value && value->type()==Object::vector) {
root=selector(*c->firstValue(), c->m_params.last());
delete c;
}
--- trunk/KDE/kdeedu/kalgebra/analitza/container.cpp #919404:919405
@@ -462,7 +462,12 @@
bool Container::isCorrect() const
{
- return m_correct && m_type==Object::container && m_cont_type!=none/* && \
!isEmpty()*/; + bool ret=m_correct && m_type==Object::container && m_cont_type!=none;
+ if(m_cont_type==Container::apply) {
+ Operator o=firstOperator();
+ ret &= o.nparams()<0 || countValues()==o.nparams();
+ }
+ return ret;
}
QString Container::tagName() const
@@ -486,3 +491,15 @@
}
return matching;
}
+
+int Container::countValues() const
+{
+ Container::const_iterator it=firstValue(), itEnd=m_params.constEnd();
+ int count=0;
+
+ for(; it!=itEnd; ++it)
+ {
+ count++;
+ }
+ return count;
+}
--- trunk/KDE/kdeedu/kalgebra/analitza/container.h #919404:919405
@@ -133,6 +133,8 @@
/** @return Returns the string associated to the container type. */
QString tagName() const;
+ int countValues() const;
+
virtual QString visit(ExpressionWriter*) const;
virtual void negate();
--- trunk/KDE/kdeedu/kalgebra/analitza/tests/analitzatest.cpp #919404:919405
@@ -259,6 +259,7 @@
QTest::newRow("scalar+card") << QStringList("card(3)");
QTest::newRow("wrong token") << QStringList("q-<");
QTest::newRow("wrong coma") << QStringList("2+2,");
+ QTest::newRow("wrong parameters") << QStringList("selector(vector{1,1/3})");
QStringList script;
script << "x:=x+1";
@@ -283,12 +284,13 @@
if(correct) {
b.setExpression(e);
+ res=b.evaluate();
correct=b.isCorrect();
- res=b.evaluate();
+ res=b.calculate();
}
-// qDebug() << "cycle" << b.isCorrect();
+// qDebug() << "cycle" << b.isCorrect() << e.toString();
}
- QVERIFY(!b.isCorrect());
+ QVERIFY(!correct);
double val;
foreach(const QString &exp, expression) {
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic