diff options
author | Benny Baumann <BenBE@geshi.org> | 2021-10-06 00:00:55 +0200 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2021-10-06 08:59:02 +0200 |
commit | 74afca7bc10ece0964720be0b59c8353e66e2576 (patch) | |
tree | 143bff43e29b186934c22cd1818bc2b247fc36fe | |
parent | 2a13e15ad0e32447fc683b54f39e9ab5f6c7f6f4 (diff) |
Validate meter configuration before proceeding
-rw-r--r-- | Settings.c | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -61,6 +61,29 @@ static void Settings_readMeterModes(Settings* this, const char* line, unsigned i this->hColumns[column].modes = modes; } +static bool Settings_validateMeters(Settings* this) { + const size_t colCount = HeaderLayout_getColumns(this->hLayout); + + for (size_t column = 0; column < colCount; column++) { + char** names = this->hColumns[column].names; + const int* modes = this->hColumns[column].modes; + const size_t len = this->hColumns[column].len; + + if (!names || !modes || !len) + return false; + + // Check for each mode there is an entry with a non-NULL name + for (size_t meterIdx = 0; meterIdx < len; meterIdx++) + if (!names[meterIdx]) + return false; + + if (names[len]) + return false; + } + + return true; +} + static void Settings_defaultMeters(Settings* this, unsigned int initialCpuCount) { int sizes[] = { 3, 3 }; @@ -313,7 +336,7 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini String_freeArray(option); } fclose(fd); - if (!didReadMeters) { + if (!didReadMeters || !Settings_validateMeters(this)) { Settings_defaultMeters(this, initialCpuCount); } return didReadAny; |