diff --git a/include/CLI/TypeTools.hpp b/include/CLI/TypeTools.hpp index f44f26720..0d2daef80 100644 --- a/include/CLI/TypeTools.hpp +++ b/include/CLI/TypeTools.hpp @@ -857,11 +857,11 @@ inline std::string type_name() { /// Convert to an unsigned integral template ::value, detail::enabler> = detail::dummy> -bool integral_conversion(const std::string& input, T& output) noexcept { - if (input.empty() || input.front() == '-') { +bool integral_conversion(const std::string &input, T &output) noexcept { + if(input.empty() || input.front() == '-') { return false; } - char* val{nullptr}; + char *val{nullptr}; errno = 0; std::uint64_t output_ll = std::strtoull(input.c_str(), &val, 0); if(errno == ERANGE) { @@ -905,7 +905,7 @@ bool integral_conversion(const std::string &input, T &output) noexcept { } /// Convert a flag into an integer value typically binary flags sets errno to nonzero if conversion failed -inline std::int64_t to_flag_value(std::string val) noexcept{ +inline std::int64_t to_flag_value(std::string val) noexcept { static const std::string trueString("true"); static const std::string falseString("false"); if(val == trueString) { @@ -933,7 +933,7 @@ inline std::int64_t to_flag_value(std::string val) noexcept{ ret = 1; break; default: - errno=EINVAL; + errno = EINVAL; return -1; } return ret; @@ -945,8 +945,8 @@ inline std::int64_t to_flag_value(std::string val) noexcept{ } else { char *loc_ptr{nullptr}; ret = std::strtoll(val.c_str(), &loc_ptr, 0); - if(loc_ptr != (val.c_str() + val.size()) && errno==0) { - errno=EINVAL; + if(loc_ptr != (val.c_str() + val.size()) && errno == 0) { + errno = EINVAL; } } return ret; @@ -975,19 +975,14 @@ bool lexical_cast(const std::string &input, T &output) { /// Boolean values template ::value == object_category::boolean_value, detail::enabler> = detail::dummy> -bool lexical_cast(const std::string& input, T& output) { - errno=0; +bool lexical_cast(const std::string &input, T &output) { + errno = 0; auto out = to_flag_value(input); - if (errno==0) - { + if(errno == 0) { output = (out > 0); - } - else if (errno==ERANGE) - { + } else if(errno == ERANGE) { output = (input[0] != '-'); - } - else - { + } else { return false; } return true; @@ -1646,14 +1641,13 @@ inline std::string sum_string_vector(const std::vector &values) { double tv{0.0}; auto comp = lexical_cast(arg, tv); if(!comp) { - errno=0; - auto fv=detail::to_flag_value(arg); - fail=(errno!=0); - if (fail) - { - break; - } - tv = static_cast(fv); + errno = 0; + auto fv = detail::to_flag_value(arg); + fail = (errno != 0); + if(fail) { + break; + } + tv = static_cast(fv); } val += tv; } diff --git a/include/CLI/impl/Option_inl.hpp b/include/CLI/impl/Option_inl.hpp index 07102eed3..2a7058823 100644 --- a/include/CLI/impl/Option_inl.hpp +++ b/include/CLI/impl/Option_inl.hpp @@ -389,10 +389,10 @@ CLI11_NODISCARD CLI11_INLINE std::string Option::get_flag_value(const std::strin return input_value; } if(default_flag_values_[static_cast(ind)].second == falseString) { - errno=0; + errno = 0; auto val = detail::to_flag_value(input_value); - if (errno != 0) { - errno=0; + if(errno != 0) { + errno = 0; return input_value; } return (val == 1) ? falseString : (val == (-1) ? trueString : std::to_string(-val)); diff --git a/tests/FuzzFailTest.cpp b/tests/FuzzFailTest.cpp index 74325ef24..1b14fc8a5 100644 --- a/tests/FuzzFailTest.cpp +++ b/tests/FuzzFailTest.cpp @@ -46,7 +46,6 @@ TEST_CASE("app_fail") { } } - TEST_CASE("file_fail") { CLI::FuzzApp fuzzdata; auto app = fuzzdata.generateApp(); @@ -54,8 +53,8 @@ TEST_CASE("file_fail") { int index = GENERATE(range(1, 2)); auto parseData = loadFailureFile("fuzz_file_fail", index); std::stringstream out(parseData); - try { - app->parse_from_stream(out); - } catch(const CLI::ParseError & /*e*/) { - } + try { + app->parse_from_stream(out); + } catch(const CLI::ParseError & /*e*/) { + } } diff --git a/tests/HelpersTest.cpp b/tests/HelpersTest.cpp index 42f206c72..49124aa74 100644 --- a/tests/HelpersTest.cpp +++ b/tests/HelpersTest.cpp @@ -202,23 +202,24 @@ TEST_CASE("StringTools: Modify3", "[helpers]") { TEST_CASE("StringTools: flagValues", "[helpers]") { CHECK(-1 == CLI::detail::to_flag_value("0")); - CHECK(errno==0); + CHECK(errno == 0); CHECK(1 == CLI::detail::to_flag_value("t")); CHECK(1 == CLI::detail::to_flag_value("1")); CHECK(6 == CLI::detail::to_flag_value("6")); CHECK(-6 == CLI::detail::to_flag_value("-6")); CHECK(-1 == CLI::detail::to_flag_value("false")); CHECK(1 == CLI::detail::to_flag_value("YES")); - errno=0; + errno = 0; CLI::detail::to_flag_value("frog"); - CHECK(errno==EINVAL); - errno=0; + CHECK(errno == EINVAL); + errno = 0; CLI::detail::to_flag_value("q"); - CHECK(errno==EINVAL); - errno=0; - CLI::detail::to_flag_value("77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"); - CHECK(errno==ERANGE); - errno=0; + CHECK(errno == EINVAL); + errno = 0; + CLI::detail::to_flag_value( + "77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"); + CHECK(errno == ERANGE); + errno = 0; CHECK(-1 == CLI::detail::to_flag_value("NO")); CHECK(475555233 == CLI::detail::to_flag_value("475555233")); } diff --git a/tests/fuzzFail/fuzz_file_fail1 b/tests/fuzzFail/fuzz_file_fail1 index 4a4fe827d..06b1c382f 100644 --- a/tests/fuzzFail/fuzz_file_fail1 +++ b/tests/fuzzFail/fuzz_file_fail1 @@ -1 +1 @@ -nflag2=555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"=" \ No newline at end of file +nflag2=555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"="