mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-30 12:10:03 +02:00
[poincare] Fix Store, Symbol and Context to store only scalar in A-Z and
avoid nullptr dereferencing Change-Id: I184cba6cf3e2fd5329dce20852f286de93ad6a82
This commit is contained in:
@@ -57,12 +57,18 @@ const Expression * GlobalContext::expressionForSymbol(const Symbol * symbol) {
|
||||
|
||||
void GlobalContext::setExpressionForSymbolName(Expression * expression, const Symbol * symbol) {
|
||||
int index = symbolIndex(symbol);
|
||||
assert(expression->type() == Expression::Type::Complex);
|
||||
if (index < 0 || index >= k_maxNumberOfScalarExpressions) {
|
||||
return;
|
||||
}
|
||||
if (m_expressions[index] != nullptr) {
|
||||
delete m_expressions[index];
|
||||
m_expressions[index] = nullptr;
|
||||
}
|
||||
m_expressions[index] = expression->clone();
|
||||
if (expression->type() == Expression::Type::Complex) {
|
||||
m_expressions[index] = expression->clone();
|
||||
} else {
|
||||
m_expressions[index] = new Complex(Complex::Float(NAN));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,7 +71,8 @@ Expression * Store::privateEvaluate(Context& context, AngleUnit angleUnit) const
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
Expression * valueEvaluation = m_value->evaluate(context, angleUnit);
|
||||
context.setExpressionForSymbolName(valueEvaluation, m_symbol);
|
||||
return valueEvaluation;
|
||||
delete valueEvaluation;
|
||||
return context.expressionForSymbol(m_symbol)->clone();
|
||||
}
|
||||
|
||||
float Store::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/context.h>
|
||||
#include <poincare/complex.h>
|
||||
#include "layout/baseline_relative_layout.h"
|
||||
#include "layout/string_layout.h"
|
||||
extern "C" {
|
||||
@@ -26,9 +27,9 @@ float Symbol::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
Expression * Symbol::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
if (context.expressionForSymbol(this) != nullptr) {
|
||||
return context.expressionForSymbol(this)->evaluate(context, angleUnit);
|
||||
return context.expressionForSymbol(this)->evaluate(context, angleUnit)->clone();
|
||||
}
|
||||
return nullptr;
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
|
||||
Expression::Type Symbol::type() const {
|
||||
|
||||
Reference in New Issue
Block a user