Skip to content

Commit f927def

Browse files
authored
Handle nCategories == 0 in setDebugLogging() (#330)
fixes #77
1 parent 03cd56f commit f927def

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/cosimulation.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,24 +163,33 @@ bool nullPointer(ModelInstance* comp, const char *f, const char *arg, const void
163163

164164
Status setDebugLogging(ModelInstance *comp, bool loggingOn, size_t nCategories, const char * const categories[]) {
165165

166-
if (loggingOn) {
166+
if (nCategories > 0) {
167+
168+
if (categories == NULL) {
169+
logError(comp, "Argument categories must not be NULL.");
170+
return Error;
171+
}
172+
167173
for (size_t i = 0; i < nCategories; i++) {
174+
168175
if (categories[i] == NULL) {
169-
logError(comp, "Log category[%d] must not be NULL", i);
176+
logError(comp, "Argument categories[%zu] must not be NULL.", i);
170177
return Error;
171178
} else if (strcmp(categories[i], "logEvents") == 0) {
172-
comp->logEvents = true;
179+
comp->logEvents = loggingOn;
173180
} else if (strcmp(categories[i], "logStatusError") == 0) {
174-
comp->logErrors = true;
181+
comp->logErrors = loggingOn;
175182
} else {
176-
logError(comp, "Log category[%d] must be one of logEvents or logStatusError but was %s", i, categories[i]);
183+
logError(comp, "Log categories[%zu] must be one of \"logEvents\" or \"logStatusError\" but was \"%s\".", i, categories[i]);
177184
return Error;
178185
}
179186
}
187+
180188
} else {
181-
// disable logging
182-
comp->logEvents = false;
183-
comp->logErrors = false;
189+
190+
comp->logEvents = loggingOn;
191+
comp->logErrors = loggingOn;
192+
184193
}
185194

186195
return OK;

0 commit comments

Comments
 (0)