mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Fix getPolynomialCoefficients to avoid overflowing the
coefficients table
This commit is contained in:
@@ -37,7 +37,7 @@ int Addition::polynomialDegree(char symbolName) const {
|
||||
|
||||
int Addition::getPolynomialCoefficients(char symbolName, Expression * coefficients[]) const {
|
||||
int deg = polynomialDegree(symbolName);
|
||||
if (deg < 0 || deg > k_maxNumberOfPolynomialCoefficients-1) {
|
||||
if (deg < 0 || deg > k_maxPolynomialDegree) {
|
||||
return -1;
|
||||
}
|
||||
for (int k = 0; k < deg+1; k++) {
|
||||
@@ -46,7 +46,7 @@ int Addition::getPolynomialCoefficients(char symbolName, Expression * coefficien
|
||||
Expression * intermediateCoefficients[k_maxNumberOfPolynomialCoefficients];
|
||||
for (int i = 0; i < numberOfOperands(); i++) {
|
||||
int d = operand(i)->getPolynomialCoefficients(symbolName, intermediateCoefficients);
|
||||
assert(d < k_maxNumberOfPolynomialCoefficients-1);
|
||||
assert(d < k_maxNumberOfPolynomialCoefficients);
|
||||
for (int j = 0; j < d+1; j++) {
|
||||
static_cast<Addition *>(coefficients[j])->addOperand(intermediateCoefficients[j]);
|
||||
}
|
||||
|
||||
@@ -45,15 +45,15 @@ int Multiplication::polynomialDegree(char symbolName) const {
|
||||
|
||||
int Multiplication::getPolynomialCoefficients(char symbolName, Expression * coefficients[]) const {
|
||||
int deg = polynomialDegree(symbolName);
|
||||
if (deg < 0 || deg + 1 > k_maxNumberOfPolynomialCoefficients) {
|
||||
if (deg < 0 || deg > k_maxPolynomialDegree) {
|
||||
return -1;
|
||||
}
|
||||
int degA = operand(0)->getPolynomialCoefficients(symbolName, coefficients);
|
||||
assert(degA + 1 <= k_maxNumberOfPolynomialCoefficients);
|
||||
assert(degA <= k_maxPolynomialDegree);
|
||||
Expression * intermediateCoefficients[k_maxNumberOfPolynomialCoefficients];
|
||||
for (int i = 1; i < numberOfOperands(); i++) {
|
||||
int degB = operand(i)->getPolynomialCoefficients(symbolName, intermediateCoefficients);
|
||||
assert(degB + 1 <= k_maxNumberOfPolynomialCoefficients);
|
||||
assert(degB <= k_maxPolynomialDegree);
|
||||
for (int j = deg; j > 0; j--) {
|
||||
Addition * a = new Addition();
|
||||
for (int l = 0; l <= j; l++) {
|
||||
|
||||
@@ -95,7 +95,7 @@ int Power::getPolynomialCoefficients(char symbolName, Expression * coefficients[
|
||||
return -1;
|
||||
}
|
||||
int n = r->numerator().extractedInt();
|
||||
if (n < k_maxNumberOfPolynomialCoefficients) {
|
||||
if (n <= k_maxPolynomialDegree) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
coefficients[i] = new Rational(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user