diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index 0155c6c5e..a22b91802 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -137,7 +137,7 @@ public: * the variables hold in 'variables'. Otherwise, it fills 'coefficients' with * the coefficients of the variables hold in 'variables' (following the same * order) and 'constant' with the constant of the expression. */ - bool getLinearCoefficients(char * variables, Expression coefficients[], Expression constant[], Context & context, Preferences::AngleUnit angleUnit) const; + bool getLinearCoefficients(char variables[][], Expression coefficients[], Expression constant[], Context & context, Preferences::AngleUnit angleUnit) const; /* getPolynomialCoefficients fills the table coefficients with the expressions * of the first 3 polynomial coefficients and return polynomialDegree. * coefficients has up to 3 entries. It supposed to be called on Reduced diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index d6c98b30d..ebb6afac0 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -101,24 +101,21 @@ bool Expression::IsMatrix(const Expression e, Context & context) { return e.type() == ExpressionNode::Type::Matrix || e.type() == ExpressionNode::Type::ConfidenceInterval || e.type() == ExpressionNode::Type::MatrixDimension || e.type() == ExpressionNode::Type::PredictionInterval || e.type() == ExpressionNode::Type::MatrixInverse || e.type() == ExpressionNode::Type::MatrixTranspose || (e.type() == ExpressionNode::Type::Symbol && Symbol::isMatrixSymbol(static_cast(e).name())); } -bool Expression::getLinearCoefficients(char * variables, Expression coefficients[], Expression constant[], Context & context, Preferences::AngleUnit angleUnit) const { +bool Expression::getLinearCoefficients(char variables[], Expression coefficients[], Expression constant[], Context & context, Preferences::AngleUnit angleUnit) const { assert(!recursivelyMatches(IsMatrix, context)); - char * x = variables; - while (*x != 0) { - const char symbol[] = {*x, 0}; - int degree = polynomialDegree(context, symbol); + int index = 0; + while (variables[index][0] != 0) { + int degree = polynomialDegree(context, variables[index]); if (degree > 1 || degree < 0) { return false; } - x++; + index++; } Expression equation = *this; - x = variables; int index = 0; Expression polynomialCoefficients[k_maxNumberOfPolynomialCoefficients]; - while (*x != 0) { - const char symbol[] = {*x, 0}; - int degree = equation.getPolynomialReducedCoefficients(symbol, polynomialCoefficients, context, angleUnit); + while (variables[index][0] != 0) { + int degree = equation.getPolynomialReducedCoefficients(variables[index], polynomialCoefficients, context, angleUnit); switch (degree) { case 0: coefficients[index] = Rational(0); @@ -137,7 +134,6 @@ bool Expression::getLinearCoefficients(char * variables, Expression coefficients * The equation supposed to be linear in all variables, so we can look for * the coefficients linked to the other variables in a_0. */ equation = polynomialCoefficients[0]; - x++; index++; } constant[0] = Opposite(equation.clone()).deepReduce(context, angleUnit);