Skip to content

Commit 81a5066

Browse files
authored
[C/OMEdit] Handle NULL flag names/descriptions (#15679)
* [C] Make readFlag handle NULL names/desc * [OMEdit] Make get flags handle NULL names/desc
1 parent bfb335b commit 81a5066

3 files changed

Lines changed: 29 additions & 15 deletions

File tree

OMCompiler/SimulationRuntime/c/simulation/simulation_runtime.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,17 @@ static void readFlag(int *flag, int max, const char *value, const char *flagName
306306
}
307307

308308
for (i=1; i<max; ++i) {
309-
if (0 == strcmp(value, names[i])) {
309+
if (names[i] != NULL && 0 == strcmp(value, names[i])) {
310310
*flag = i;
311311
return;
312312
}
313313
}
314314

315315
warningStreamPrint(OMC_LOG_STDOUT, 1, "unrecognized option %s=%s, current options are:", flagName, value);
316316
for (i=1; i<max; ++i) {
317-
warningStreamPrint(OMC_LOG_STDOUT, 0, "%-18s [%s]", names[i], desc[i]);
317+
if (names[i] != NULL) {
318+
warningStreamPrint(OMC_LOG_STDOUT, 0, "%-19s [%s]", names[i], desc[i] != NULL ? desc[i] : "");
319+
}
318320
}
319321
messageCloseWarning(OMC_LOG_STDOUT);
320322
throwStreamPrint(NULL,"see last warning");

OMCompiler/SimulationRuntime/c/simulation/solver/gbode_nls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ void freeRK_NLS_DATA(NONLINEAR_SYSTEM_DATA* nlsData)
462462
gbInternalNlsFree(dataSolver->ordinaryData);
463463
break;
464464
default:
465-
throwStreamPrint(NULL, "Not handled NONLINEAR_SOLVER in gbode_freeData. Are we leaking memroy?");
465+
throwStreamPrint(NULL, "Not handled NONLINEAR_SOLVER in gbode_freeData. Are we leaking memory?");
466466
}
467467
free(dataSolver);
468468
freeNlsDataGB(nlsData);

OMEdit/OMEditLIB/OMC/OMCProxy.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,8 +3119,10 @@ QStringList OMCProxy::getEnumerationLiterals(QString className)
31193119
void OMCProxy::getSolverMethods(QStringList *methods, QStringList *descriptions)
31203120
{
31213121
for (int i = S_UNKNOWN + 1 ; i < S_MAX ; i++) {
3122-
*methods << SOLVER_METHOD_NAME[i];
3123-
*descriptions << SOLVER_METHOD_DESC[i];
3122+
if (SOLVER_METHOD_NAME[i] != NULL) {
3123+
*methods << SOLVER_METHOD_NAME[i];
3124+
*descriptions << (SOLVER_METHOD_DESC[i] != NULL ? SOLVER_METHOD_DESC[i] : "");
3125+
}
31243126
}
31253127
}
31263128

@@ -3133,8 +3135,10 @@ void OMCProxy::getSolverMethods(QStringList *methods, QStringList *descriptions)
31333135
void OMCProxy::getJacobianMethods(QStringList *methods, QStringList *descriptions)
31343136
{
31353137
for (int i = JAC_UNKNOWN + 1 ; i < JAC_MAX ; i++) {
3136-
*methods << JACOBIAN_METHOD_NAME[i];
3137-
*descriptions << JACOBIAN_METHOD_DESC[i];
3138+
if (JACOBIAN_METHOD_NAME[i] != NULL) {
3139+
*methods << JACOBIAN_METHOD_NAME[i];
3140+
*descriptions << (JACOBIAN_METHOD_DESC[i] != NULL ? JACOBIAN_METHOD_DESC[i] : "");
3141+
}
31383142
}
31393143
}
31403144

@@ -3157,8 +3161,10 @@ QString OMCProxy::getJacobianFlagDetailedDescription()
31573161
void OMCProxy::getInitializationMethods(QStringList *methods, QStringList *descriptions)
31583162
{
31593163
for (int i = IIM_UNKNOWN + 1 ; i < IIM_MAX ; i++) {
3160-
*methods << INIT_METHOD_NAME[i];
3161-
*descriptions << INIT_METHOD_DESC[i];
3164+
if (INIT_METHOD_NAME[i] != NULL) {
3165+
*methods << INIT_METHOD_NAME[i];
3166+
*descriptions << (INIT_METHOD_DESC[i] != NULL ? INIT_METHOD_DESC[i] : "");
3167+
}
31623168
}
31633169
}
31643170

@@ -3171,8 +3177,10 @@ void OMCProxy::getInitializationMethods(QStringList *methods, QStringList *descr
31713177
void OMCProxy::getLinearSolvers(QStringList *methods, QStringList *descriptions)
31723178
{
31733179
for (int i = LS_NONE + 1 ; i < LS_MAX ; i++) {
3174-
*methods << LS_NAME[i];
3175-
*descriptions << LS_DESC[i];
3180+
if (LS_NAME[i] != NULL) {
3181+
*methods << LS_NAME[i];
3182+
*descriptions << (LS_DESC[i] != NULL ? LS_DESC[i] : "");
3183+
}
31763184
}
31773185
}
31783186

@@ -3185,8 +3193,10 @@ void OMCProxy::getLinearSolvers(QStringList *methods, QStringList *descriptions)
31853193
void OMCProxy::getNonLinearSolvers(QStringList *methods, QStringList *descriptions)
31863194
{
31873195
for (int i = NLS_NONE + 1 ; i < NLS_MAX ; i++) {
3188-
*methods << NLS_NAME[i];
3189-
*descriptions << NLS_DESC[i];
3196+
if (NLS_NAME[i] != NULL) {
3197+
*methods << NLS_NAME[i];
3198+
*descriptions << (NLS_DESC[i] != NULL ? NLS_DESC[i] : "");
3199+
}
31903200
}
31913201
}
31923202

@@ -3199,8 +3209,10 @@ void OMCProxy::getNonLinearSolvers(QStringList *methods, QStringList *descriptio
31993209
void OMCProxy::getLogStreams(QStringList *names, QStringList *descriptions)
32003210
{
32013211
for (int i = firstOMCErrorStream ; i < OMC_SIM_LOG_MAX ; i++) {
3202-
*names << OMC_LOG_STREAM_NAME[i];
3203-
*descriptions << OMC_LOG_STREAM_DESC[i];
3212+
if (OMC_LOG_STREAM_NAME[i] != NULL) {
3213+
*names << OMC_LOG_STREAM_NAME[i];
3214+
*descriptions << (OMC_LOG_STREAM_DESC[i] != NULL ? OMC_LOG_STREAM_DESC[i] : "");
3215+
}
32043216
}
32053217
}
32063218

0 commit comments

Comments
 (0)