Skip to content

Commit 747e360

Browse files
initialize logger on first call, add guard against uninitialized src ptr in set_var
1 parent 7032190 commit 747e360

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/engines_gpl/dsle/packages/src/dimr_bmi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ int set_var(const char *key, void *src_ptr) {
122122
char *vartype = NULL;
123123
char *lock_id = NULL;
124124

125+
if (src_ptr == NULL) {
126+
log_debug("set_var('%s') called with NULL src_ptr, ignoring.\n", key);
127+
return DIMR_BMI_OK;
128+
}
129+
125130
log_info("%s( \"%s\", *src_ptr = %g) called.\n", __func__, key, *(double *)src_ptr);
126131

127132
copy_key(key, keystr);

src/engines_gpl/dsle/packages/src/log/log.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ void log_init(char *name, FILE *fp) {
1616
void log_set_level(log_level_t lvl) { logger.level = lvl; }
1717

1818
static void vlog(log_level_t lvl, char *fmt, va_list ap) {
19+
if (logger.name == NULL) {
20+
log_init("dsle", stderr);
21+
}
1922
if (lvl >= logger.level && lvl <= logERROR) {
2023
FILE *stream = logger.fp ? logger.fp : stderr;
2124
fprintf(stream, "[%s] %s: ", level_strings[lvl], logger.name);

0 commit comments

Comments
 (0)