Skip to content

Commit d15db4b

Browse files
refactor: Fix unreachable code in init arg checks
Building with -Wunreachable-code-loop-increment causes a warning due to always returning on the first iteration of the loop that outputs errors on invalid args. Collect all errors, and output them in a single error message after the loop completes, resolving the warning and avoiding popup hell by outputting a seperate message for each error.
1 parent 091cc4b commit d15db4b

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/init.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,17 +964,27 @@ bool AppInitParameterInteraction()
964964

965965
// also see: InitParameterInteraction()
966966

967-
// Warn if network-specific options (-addnode, -connect, etc) are
967+
// Error if network-specific options (-addnode, -connect, etc) are
968968
// specified in default section of config file, but not overridden
969969
// on the command line or in this network's section of the config file.
970970
std::string network = gArgs.GetChainName();
971+
bilingual_str errors;
971972
for (const auto& arg : gArgs.GetUnsuitableSectionOnlyArgs()) {
972-
return InitError(strprintf(_("Config setting for %s only applied on %s network when in [%s] section."), arg, network, network));
973+
errors += strprintf(_("Config setting for %s only applied on %s network when in [%s] section.") + Untranslated("\n"), arg, network, network);
974+
}
975+
976+
if (!errors.empty()) {
977+
return InitError(errors);
973978
}
974979

975980
// Warn if unrecognized section name are present in the config file.
981+
bilingual_str warnings;
976982
for (const auto& section : gArgs.GetUnrecognizedSections()) {
977-
InitWarning(strprintf(Untranslated("%s:%i ") + _("Section [%s] is not recognized."), section.m_file, section.m_line, section.m_name));
983+
warnings += strprintf(Untranslated("%s:%i ") + _("Section [%s] is not recognized.") + Untranslated("\n"), section.m_file, section.m_line, section.m_name);
984+
}
985+
986+
if (!warnings.empty()) {
987+
InitWarning(warnings);
978988
}
979989

980990
if (!fs::is_directory(GetBlocksDir())) {

src/util/translation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ struct bilingual_str {
2323
translated += rhs.translated;
2424
return *this;
2525
}
26+
27+
bool empty() const
28+
{
29+
return original.empty();
30+
}
2631
};
2732

2833
inline bilingual_str operator+(bilingual_str lhs, const bilingual_str& rhs)

test/functional/feature_config_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_config_file_parser(self):
7171
with open(inc_conf_file2_path, 'w', encoding='utf-8') as conf:
7272
conf.write('[testnet]\n')
7373
self.restart_node(0)
74-
self.nodes[0].stop_node(expected_stderr='Warning: ' + inc_conf_file_path + ':1 Section [testnot] is not recognized.' + os.linesep + 'Warning: ' + inc_conf_file2_path + ':1 Section [testnet] is not recognized.')
74+
self.nodes[0].stop_node(expected_stderr='Warning: ' + inc_conf_file_path + ':1 Section [testnot] is not recognized.' + os.linesep + inc_conf_file2_path + ':1 Section [testnet] is not recognized.')
7575

7676
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
7777
conf.write('') # clear

0 commit comments

Comments
 (0)