From 9873d18298afbe07dfe20cb3ae36ccb40c9bc88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Thu, 28 Dec 2017 21:29:42 +0100 Subject: [PATCH] Fixed bug in ini parsing --- framework/settings.c | 9 ++++++--- framework/unit_registry.c | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/framework/settings.c b/framework/settings.c index eda681d..f32997c 100644 --- a/framework/settings.c +++ b/framework/settings.c @@ -270,7 +270,7 @@ void settings_load_ini_begin(void) void settings_load_ini_key(const char *restrict section, const char *restrict key, const char *restrict value) { -// dbg("[%s] %s = %s", section, key, value); + //dbg("[%s] %s = %s", section, key, value); static char namebuf[INI_KEY_MAX]; // SYSTEM and UNITS files must be separate. @@ -303,10 +303,13 @@ void settings_load_ini_key(const char *restrict section, const char *restrict ke const char *nameptr = strchr(section, ':'); const char *csptr = strchr(section, '@'); - if (nameptr && csptr) { + if (nameptr != NULL && csptr != NULL) { strncpy(namebuf, nameptr+1, csptr - nameptr - 1); + namebuf[csptr - nameptr - 1] = 0; uint8_t cs = (uint8_t) avr_atoi(csptr + 1); - ureg_load_unit_ini_key(namebuf, key, value, cs); + + bool res = ureg_load_unit_ini_key(namebuf, key, value, cs); + if (!res) dbg("!! error loading %s@%d.%s = %s", namebuf, (int)cs, key, value); } else { dbg("! Bad config key: [%s] %s = %s", section, key, value); } diff --git a/framework/unit_registry.c b/framework/unit_registry.c index 84dcc89..4036d71 100644 --- a/framework/unit_registry.c +++ b/framework/unit_registry.c @@ -305,8 +305,8 @@ bool ureg_load_unit_ini_key(const char *restrict name, { UlistEntry *li = ulist_head; while (li != NULL) { - if (streq(li->unit.name, name)) { - Unit *const pUnit = &li->unit; + Unit *const pUnit = &li->unit; + if (streq(pUnit->name, name)) { pUnit->callsign = callsign; return pUnit->driver->cfgLoadIni(pUnit, key, value); }