Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 1b6a960

Browse files
atrosinenkoOpenModelica-Hudson
authored andcommitted
Do not complain on NULL returned when allocating 0 objects
According to documentation on malloc/calloc, when zero allocation size is requested, it is allowed to return either unique pointer or NULL. In the latter case, FMU was previously incorrectly complaining about "out of memory". Belonging to [master]: - #2844
1 parent 52cd129 commit 1b6a960

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

SimulationRuntime/c/simulation/solver/model_help.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -894,14 +894,14 @@ void initializeDataStruc(DATA *data, threadData_t *threadData)
894894
tmpSimData.timeValue = 0;
895895
/* buffer for all variable values */
896896
tmpSimData.realVars = (modelica_real*) calloc(data->modelData->nVariablesReal, sizeof(modelica_real));
897-
assertStreamPrint(threadData, 0 != tmpSimData.realVars, "out of memory");
897+
assertStreamPrint(threadData, 0 == data->modelData->nVariablesReal || 0 != tmpSimData.realVars, "out of memory");
898898
tmpSimData.integerVars = (modelica_integer*) calloc(data->modelData->nVariablesInteger, sizeof(modelica_integer));
899-
assertStreamPrint(threadData, 0 != tmpSimData.integerVars, "out of memory");
899+
assertStreamPrint(threadData, 0 == data->modelData->nVariablesInteger || 0 != tmpSimData.integerVars, "out of memory");
900900
tmpSimData.booleanVars = (modelica_boolean*) calloc(data->modelData->nVariablesBoolean, sizeof(modelica_boolean));
901-
assertStreamPrint(threadData, 0 != tmpSimData.booleanVars, "out of memory");
901+
assertStreamPrint(threadData, 0 == data->modelData->nVariablesBoolean || 0 != tmpSimData.booleanVars, "out of memory");
902902
#if !defined(OMC_NVAR_STRING) || OMC_NVAR_STRING>0
903903
tmpSimData.stringVars = (modelica_string*) omc_alloc_interface.malloc_uncollectable(data->modelData->nVariablesString * sizeof(modelica_string));
904-
assertStreamPrint(threadData, 0 != tmpSimData.stringVars, "out of memory");
904+
assertStreamPrint(threadData, 0 == data->modelData->nVariablesString || 0 != tmpSimData.stringVars, "out of memory");
905905
#endif
906906
appendRingData(data->simulationData, &tmpSimData);
907907
}
@@ -1045,7 +1045,7 @@ void initializeDataStruc(DATA *data, threadData_t *threadData)
10451045
data->simulationInfo->extObjs = NULL;
10461046
data->simulationInfo->extObjs = (void**) calloc(data->modelData->nExtObjs, sizeof(void*));
10471047

1048-
assertStreamPrint(threadData, 0 != data->simulationInfo->extObjs, "error allocating external objects");
1048+
assertStreamPrint(threadData, 0 == data->modelData->nExtObjs || 0 != data->simulationInfo->extObjs, "error allocating external objects");
10491049

10501050
#if !defined(OMC_MINIMAL_LOGGING)
10511051
/* initial chattering info */
@@ -1083,7 +1083,7 @@ void initializeDataStruc(DATA *data, threadData_t *threadData)
10831083
/* initial delay */
10841084
#if !defined(OMC_NDELAY_EXPRESSIONS) || OMC_NDELAY_EXPRESSIONS>0
10851085
data->simulationInfo->delayStructure = (RINGBUFFER**)malloc(data->modelData->nDelayExpressions * sizeof(RINGBUFFER*));
1086-
assertStreamPrint(threadData, 0 != data->simulationInfo->delayStructure, "out of memory");
1086+
assertStreamPrint(threadData, 0 == data->modelData->nDelayExpressions || 0 != data->simulationInfo->delayStructure, "out of memory");
10871087

10881088
for(i=0; i<data->modelData->nDelayExpressions; i++)
10891089
data->simulationInfo->delayStructure[i] = allocRingBuffer(1024, sizeof(TIME_AND_VALUE));

0 commit comments

Comments
 (0)