From 7dc882f96c6ca1cffc7345302c8c6083b1523d94 Mon Sep 17 00:00:00 2001 From: OLSSON Hans Date: Tue, 3 May 2022 12:15:49 +0200 Subject: [PATCH 1/2] Try to fix crash for ModelicaTest.Tables.CombiTable2D[sv].Test2[167] when compiled with VS 2019. --- Modelica/Resources/C-Sources/ModelicaStandardTables.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modelica/Resources/C-Sources/ModelicaStandardTables.c b/Modelica/Resources/C-Sources/ModelicaStandardTables.c index 7ab0fd8bc3..3aa702e11e 100644 --- a/Modelica/Resources/C-Sources/ModelicaStandardTables.c +++ b/Modelica/Resources/C-Sources/ModelicaStandardTables.c @@ -6943,7 +6943,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]; @@ -6968,7 +6968,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]; From 91ba7ab0817776d14b4b651240496de152e792c9 Mon Sep 17 00:00:00 2001 From: Thomas Beutlich Date: Tue, 3 May 2022 17:41:17 +0200 Subject: [PATCH 2/2] Fix allocation size --- Modelica/Resources/C-Sources/ModelicaStandardTables.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Modelica/Resources/C-Sources/ModelicaStandardTables.c b/Modelica/Resources/C-Sources/ModelicaStandardTables.c index 3aa702e11e..6e96fc03aa 100644 --- a/Modelica/Resources/C-Sources/ModelicaStandardTables.c +++ b/Modelica/Resources/C-Sources/ModelicaStandardTables.c @@ -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. @@ -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; @@ -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; }