Skip to content

Commit

Permalink
Merge pull request modelica#3983 from HansOlsson/CrashSpline
Browse files Browse the repository at this point in the history
Fix index-out-of-bounds exception for splines
  • Loading branch information
MartinOtter committed Mar 12, 2023
2 parents ef08d88 + 91ba7ab commit 64b1f57
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Modelica/Resources/C-Sources/ModelicaStandardTables.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
Modelica.Blocks.Tables.CombiTable2Dv
Changelog:
May 03, 2022: by Hans Olsson, Dassault Systemes
Fixed index-out-of-bounds exception in spline
initialization of 2D tables that actually degrade
to 1D tables (ticket #3983)
Jan. 31, 2022: by Hans Olsson, Dassault Systemes
Added better support for one-sided derivatives of CombiTable2D.
Expand Down Expand Up @@ -6925,7 +6929,7 @@ static CubicHermite2D* spline2DInit(_In_ const double* table, size_t nRow,
return NULL;
}

spline = (CubicHermite2D*)malloc((nCol - 1)*sizeof(CubicHermite2D));
spline = (CubicHermite2D*)malloc((nCol - 2)*sizeof(CubicHermite2D));
if (NULL == spline) {
free(tableT);
return NULL;
Expand All @@ -6943,7 +6947,7 @@ static CubicHermite2D* spline2DInit(_In_ const double* table, size_t nRow,
return NULL;
}
/* Copy coefficients */
for (j = 0; j < nCol - 1; j++) {
for (j = 0; j < nCol - 2; j++) {
const double* c1 = spline1D[j];
double* c2 = spline[j];
c2[0] = c1[0];
Expand All @@ -6957,7 +6961,7 @@ static CubicHermite2D* spline2DInit(_In_ const double* table, size_t nRow,
size_t i;
int cols = 2;

spline = (CubicHermite2D*)malloc((nRow - 1)*sizeof(CubicHermite2D));
spline = (CubicHermite2D*)malloc((nRow - 2)*sizeof(CubicHermite2D));
if (NULL == spline) {
return NULL;
}
Expand All @@ -6968,7 +6972,7 @@ static CubicHermite2D* spline2DInit(_In_ const double* table, size_t nRow,
return NULL;
}
/* Copy coefficients */
for (i = 0; i < nRow - 1; i++) {
for (i = 0; i < nRow - 2; i++) {
const double* c1 = spline1D[i];
double* c2 = spline[i];
c2[0] = c1[0];
Expand Down

0 comments on commit 64b1f57

Please sign in to comment.