From ebfdacb0d3a4fcd51cf0c4aee35906c978923d59 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Tue, 11 Aug 2015 13:56:32 +0200 Subject: [PATCH] Introduced .cfg file format version to 2 (to prevent older cppcheck versions from failing silently when reading them), because 5b287fc849036dce9450bf5e185999c1ec62dcb7 introduced a backward-incompatible feature. Increased format version of std.cfg, which is the only cfg file that makes use of the new backward incompatible feature. Refactorization: Avoid a redundant std::string::find()-call --- cfg/std.cfg | 2 +- lib/library.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index 112ff4f3c..57e165447 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -1,5 +1,5 @@ - + true diff --git a/lib/library.cpp b/lib/library.cpp index 31933fcb3..7cc0fe1c8 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -36,12 +36,13 @@ Library::Error Library::load(const char exename[], const char path[]) { if (std::strchr(path,',') != nullptr) { std::string p(path); - while (p.find(",") != std::string::npos) { - const std::string::size_type pos = p.find(","); + std::string::size_type pos = p.find(','); + while (pos != std::string::npos) { const Error &e = load(exename, p.substr(0,pos).c_str()); if (e.errorcode != OK) return e; p = p.substr(pos+1); + pos = p.find(','); } if (!p.empty()) return load(exename, p.c_str()); @@ -111,11 +112,11 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) return Error(UNSUPPORTED_FORMAT, rootnode->Name()); const char* format_string = rootnode->Attribute("format"); - int format = 1; + int format = 1; // Assume format version 1 if nothing else is specified (very old .cfg files had no 'format' attribute) if (format_string) format = atoi(format_string); - if (format > 1) + if (format > 2 || format <= 0) return Error(UNSUPPORTED_FORMAT); std::set unknown_elements;