From 1a82981d07dbf37507a75e93d980cf559f497bbd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 17 Jul 2018 22:07:05 +0200 Subject: [PATCH] test/read_conf: validate the setting name early --- test/read_conf.cxx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/read_conf.cxx b/test/read_conf.cxx index ecc1fc731..4fc52a842 100644 --- a/test/read_conf.cxx +++ b/test/read_conf.cxx @@ -22,6 +22,7 @@ #include "fs/Path.hxx" #include "fs/Path.hxx" #include "util/PrintException.hxx" +#include "util/RuntimeError.hxx" #include #include @@ -37,14 +38,15 @@ try { const Path config_path = Path::FromFS(argv[1]); const char *name = argv[2]; + const auto option = ParseConfigOptionName(name); + if (option == ConfigOption::MAX) + throw FormatRuntimeError("Unknown setting: %s", name); + config_global_init(); ReadConfigFile(config_path); - ConfigOption option = ParseConfigOptionName(name); - const char *value = option != ConfigOption::MAX - ? config_get_string(option) - : nullptr; + const char *value = config_get_string(option); int ret; if (value != NULL) { printf("%s\n", value);