From a6882a998e7a983715da58f32b87cdf3199c06c3 Mon Sep 17 00:00:00 2001 From: Sunjay Bhatia Date: Mon, 9 Dec 2019 17:14:46 -0500 Subject: [PATCH 1/3] Correct type for std::array size() result The std::array API uses std::size_t for the size() nelts count. This is a larger sized int than 'int', which causes this code to break on Windows compilation. Use the stdcxx type for conformance and portability. Signed-off-by: Sunjay Bhatia Signed-off-by: William A Rowe Jr --- source/server/options_impl.cc | 2 +- source/server/options_impl.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/server/options_impl.cc b/source/server/options_impl.cc index b12863b10112..c96f127fee1c 100644 --- a/source/server/options_impl.cc +++ b/source/server/options_impl.cc @@ -19,7 +19,7 @@ namespace Envoy { namespace { -std::vector toArgsVector(int argc, const char* const* argv) { +std::vector toArgsVector(std::size_t argc, const char* const* argv) { std::vector args; for (int i = 0; i < argc; ++i) { args.emplace_back(argv[i]); diff --git a/source/server/options_impl.h b/source/server/options_impl.h index b5a209329d21..0789f4992937 100644 --- a/source/server/options_impl.h +++ b/source/server/options_impl.h @@ -30,7 +30,8 @@ class OptionsImpl : public Server::Options, protected Logger::Loggable Date: Mon, 9 Dec 2019 17:46:47 -0500 Subject: [PATCH 2/3] Add missing type changes to prior patch Signed-off-by: Sunjay Bhatia Signed-off-by: William A Rowe Jr --- source/server/options_impl.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/server/options_impl.cc b/source/server/options_impl.cc index c96f127fee1c..ef964e082995 100644 --- a/source/server/options_impl.cc +++ b/source/server/options_impl.cc @@ -21,14 +21,14 @@ namespace Envoy { namespace { std::vector toArgsVector(std::size_t argc, const char* const* argv) { std::vector args; - for (int i = 0; i < argc; ++i) { + for (size_t i = 0; i < argc; ++i) { args.emplace_back(argv[i]); } return args; } } // namespace -OptionsImpl::OptionsImpl(int argc, const char* const* argv, +OptionsImpl::OptionsImpl(std::size_t argc, const char* const* argv, const HotRestartVersionCb& hot_restart_version_cb, spdlog::level::level_enum default_log_level) : OptionsImpl(toArgsVector(argc, argv), hot_restart_version_cb, default_log_level) {} From 3310fd2f1cb11904fcb0c73842a726260d480e51 Mon Sep 17 00:00:00 2001 From: William A Rowe Jr Date: Wed, 11 Dec 2019 18:21:49 -0500 Subject: [PATCH 3/3] Toggle the OptionsImpl argc from std::array to main() argc - Reverts the prior proposal - Overrides the std::array in tests to emulate argc/argv from main() Signed-off-by: William A Rowe Jr --- source/server/options_impl.cc | 6 +++--- source/server/options_impl.h | 3 +-- test/server/options_impl_test.cc | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/source/server/options_impl.cc b/source/server/options_impl.cc index ef964e082995..b12863b10112 100644 --- a/source/server/options_impl.cc +++ b/source/server/options_impl.cc @@ -19,16 +19,16 @@ namespace Envoy { namespace { -std::vector toArgsVector(std::size_t argc, const char* const* argv) { +std::vector toArgsVector(int argc, const char* const* argv) { std::vector args; - for (size_t i = 0; i < argc; ++i) { + for (int i = 0; i < argc; ++i) { args.emplace_back(argv[i]); } return args; } } // namespace -OptionsImpl::OptionsImpl(std::size_t argc, const char* const* argv, +OptionsImpl::OptionsImpl(int argc, const char* const* argv, const HotRestartVersionCb& hot_restart_version_cb, spdlog::level::level_enum default_log_level) : OptionsImpl(toArgsVector(argc, argv), hot_restart_version_cb, default_log_level) {} diff --git a/source/server/options_impl.h b/source/server/options_impl.h index 0789f4992937..b5a209329d21 100644 --- a/source/server/options_impl.h +++ b/source/server/options_impl.h @@ -30,8 +30,7 @@ class OptionsImpl : public Server::Options, protected Logger::Loggable args{"envoy", "-c", "hello"}; std::unique_ptr options = std::make_unique( - args.size(), args.data(), [](bool) { return "1"; }, spdlog::level::warn); + static_cast(args.size()), args.data(), [](bool) { return "1"; }, spdlog::level::warn); // Spot check that the arguments were parsed. EXPECT_EQ("hello", options->configPath()); } @@ -260,7 +260,7 @@ TEST_F(OptionsImplTest, OptionsFromArgv) { TEST_F(OptionsImplTest, OptionsFromArgvPrefix) { const std::array args{"envoy", "-c", "hello", "--admin-address-path", "goodbye"}; std::unique_ptr options = std::make_unique( - args.size() - 2, // Pass in only a prefix of the args + static_cast(args.size()) - 2, // Pass in only a prefix of the args args.data(), [](bool) { return "1"; }, spdlog::level::warn); EXPECT_EQ("hello", options->configPath()); // This should still have the default value since the extra arguments are