From c8d8139e6dc5e1290015080e3b36dee22090a7cf Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Sep 2021 19:33:38 +0100 Subject: Add -Wconversion and -Wsign-conversion --- Jamroot.jam | 2 ++ icespider/common/pathparts.cpp | 4 ++-- icespider/common/pathparts.h | 2 +- icespider/compile/routeCompiler.cpp | 2 +- icespider/core/ihttpRequest.cpp | 4 ++-- icespider/core/xwwwFormUrlEncoded.cpp | 20 ++++++++++---------- icespider/fileSessions/fileSessions.cpp | 8 ++++---- icespider/unittests/testApp.cpp | 2 +- 8 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Jamroot.jam b/Jamroot.jam index a6e17a5..82324ca 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -22,6 +22,8 @@ project debug:-Wcast-align debug:-Wunused debug:-Woverloaded-virtual + debug:-Wconversion + debug:-Wsign-conversion debug:-Wnull-dereference debug:-Wdouble-promotion debug:-Wformat=2 diff --git a/icespider/common/pathparts.cpp b/icespider/common/pathparts.cpp index 905e4d5..9318088 100644 --- a/icespider/common/pathparts.cpp +++ b/icespider/common/pathparts.cpp @@ -13,7 +13,7 @@ namespace IceSpider { return; } for (auto pi = ba::make_split_iterator(relp, slash); pi != decltype(pi)(); ++pi) { - std::string_view pp(pi->begin(), pi->end() - pi->begin()); + std::string_view pp {pi->begin(), pi->end()}; if (pp.front() == '{' && pp.back() == '}') { parts.push_back(std::make_unique(pp)); } @@ -23,7 +23,7 @@ namespace IceSpider { } } - unsigned int + std::size_t Path::pathElementCount() const { return parts.size(); diff --git a/icespider/common/pathparts.h b/icespider/common/pathparts.h index 4aaf926..2c6aaa9 100644 --- a/icespider/common/pathparts.h +++ b/icespider/common/pathparts.h @@ -44,7 +44,7 @@ namespace IceSpider { std::string_view path; - [[nodiscard]] unsigned int pathElementCount() const; + [[nodiscard]] std::size_t pathElementCount() const; PathParts parts; }; diff --git a/icespider/compile/routeCompiler.cpp b/icespider/compile/routeCompiler.cpp index a5be4ac..c2b1731 100644 --- a/icespider/compile/routeCompiler.cpp +++ b/icespider/compile/routeCompiler.cpp @@ -419,7 +419,7 @@ namespace IceSpider { if (p.second->source == ParameterSource::URL) { fputs(",\n", output); Path path(r.second->path); - unsigned int idx = -1; + long idx = -1; for (const auto & pp : path.parts) { if (auto par = dynamic_cast(pp.get())) { if (par->name == *p.second->key) { diff --git a/icespider/core/ihttpRequest.cpp b/icespider/core/ihttpRequest.cpp index 9459f60..7a72a96 100644 --- a/icespider/core/ihttpRequest.cpp +++ b/icespider/core/ihttpRequest.cpp @@ -42,7 +42,7 @@ namespace IceSpider { throw Http400_BadRequest(); } Accepted accepts; - accepts.reserve(std::count(acceptHdr.begin(), acceptHdr.end(), ',') + 1); + accepts.reserve(static_cast(std::count(acceptHdr.begin(), acceptHdr.end(), ',') + 1)); auto upto = [](std::string_view & in, const std::string_view term, bool req) { remove_leading(in, ' '); @@ -84,7 +84,7 @@ namespace IceSpider { throw Http400_BadRequest(); } const auto qs = upto(acceptHdr, ",", false).first; - a.q = std::atof(std::string(qs).c_str()); + a.q = std::strtof(std::string(qs).c_str(), nullptr); if (a.q <= 0.0F || a.q > 1.0F) { throw Http400_BadRequest(); } diff --git a/icespider/core/xwwwFormUrlEncoded.cpp b/icespider/core/xwwwFormUrlEncoded.cpp index b39c944..e594bb0 100644 --- a/icespider/core/xwwwFormUrlEncoded.cpp +++ b/icespider/core/xwwwFormUrlEncoded.cpp @@ -13,7 +13,7 @@ using HexPair = std::pair; using HexOut = std::array; constexpr auto hexout = []() { auto hexchar = [](auto c) { - return c < 10 ? '0' + c : 'a' - 10 + c; + return static_cast(c < 10 ? '0' + c : 'a' - 10 + c); }; HexOut out {}; for (unsigned int n = 0; n < CHARMAX; n++) { @@ -58,10 +58,10 @@ static_assert(hexout['?'].second == 'f'); constexpr std::array, CHARMAX> hextable = []() { std::array, CHARMAX> hextable {}; - for (int n = '0'; n <= '9'; n++) { + for (size_t n = '0'; n <= '9'; n++) { hextable[n] = {n - '0'}; } - for (int n = 'a'; n <= 'f'; n++) { + for (size_t n = 'a'; n <= 'f'; n++) { hextable[n] = hextable[n - 32] = {n - 'a' + 10}; } return hextable; @@ -81,13 +81,13 @@ static_assert(!hextable['G'].has_value()); using HexIn = std::array, CHARMAX>; constexpr HexIn hexin = []() { HexIn hexin {}; - auto firstHex = std::min({'0', 'a', 'A'}); - auto lastHex = std::max({'9', 'f', 'F'}); + size_t firstHex = std::min({'0', 'a', 'A'}); + size_t lastHex = std::max({'9', 'f', 'F'}); for (auto first = firstHex; first <= lastHex; first++) { if (const auto ch1 = hextable[first]) { for (auto second = firstHex; second <= lastHex; second++) { if (const auto ch2 = hextable[second]) { - hexin[first][second] = (*ch1 << 4U) + *ch2; + hexin[first][second] = static_cast((*ch1 << 4U) + *ch2); } } } @@ -187,7 +187,7 @@ namespace IceSpider { constexpr auto urlencoderange = [](auto && o, auto i, auto e) { while (i != e) { - const auto & out = hexout[*i]; + const auto & out = hexout[static_cast(*i)]; if (out.second) { o = '%'; o = out.first; @@ -207,7 +207,7 @@ namespace IceSpider { XWwwFormUrlEncoded::urlencode(std::string_view::const_iterator i, std::string_view::const_iterator e) { std::string o; - o.reserve(std::distance(i, e)); + o.reserve(static_cast(std::distance(i, e))); urlencoderange(std::back_inserter(o), i, e); return o; } @@ -223,14 +223,14 @@ namespace IceSpider { XWwwFormUrlEncoded::urldecode(std::string_view::const_iterator i, std::string_view::const_iterator e) { std::string t; - t.reserve(std::distance(i, e)); + t.reserve(static_cast(std::distance(i, e))); while (i != e) { switch (*i) { case '+': t += ' '; break; case '%': - if (const auto ch = hexin[*(i + 1)][*(i + 2)]) { + if (const auto ch = hexin[static_cast(*(i + 1))][static_cast(*(i + 2))]) { t += ch; } else { diff --git a/icespider/fileSessions/fileSessions.cpp b/icespider/fileSessions/fileSessions.cpp index 1fcdd24..afbb18d 100644 --- a/icespider/fileSessions/fileSessions.cpp +++ b/icespider/fileSessions/fileSessions.cpp @@ -19,7 +19,7 @@ namespace IceSpider { public: FileSessions(Ice::CommunicatorPtr c, const Ice::PropertiesPtr & p) : ic(std::move(c)), root(p->getProperty("IceSpider.FileSessions.Path")), - duration(p->getPropertyAsIntWithDefault("IceSpider.FileSessions.Duration", 3600)) + duration(static_cast(p->getPropertyAsIntWithDefault("IceSpider.FileSessions.Duration", 3600))) { if (!root.empty() && !std::filesystem::exists(root)) { std::filesystem::create_directories(root); @@ -88,11 +88,11 @@ namespace IceSpider { s->lastUsed = time(nullptr); Ice::OutputStream buf(ic); buf.write(s); - auto range = buf.finished(); + const auto range = buf.finished(); // NOLINTNEXTLINE(hicpp-signed-bitwise) AdHoc::FileUtils::FileHandle f(root / s->id, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); sysassert(flock(f.fh, LOCK_EX), -1); - sysassert(pwrite(f.fh, range.first, range.second - range.first, 0), -1); + sysassert(pwrite(f.fh, range.first, static_cast(range.second - range.first), 0), -1); sysassert(ftruncate(f.fh, range.second - range.first), -1); sysassert(flock(f.fh, LOCK_UN), -1); } @@ -156,7 +156,7 @@ namespace IceSpider { Ice::CommunicatorPtr ic; const std::filesystem::path root; - const Ice::Int duration; + const Ice::Short duration; }; } NAMEDFACTORY("IceSpider-FileSessions", IceSpider::FileSessions, IceSpider::PluginFactory); diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp index 46fda40..1ce26f4 100644 --- a/icespider/unittests/testApp.cpp +++ b/icespider/unittests/testApp.cpp @@ -526,7 +526,7 @@ BOOST_AUTO_TEST_CASE(testErrorHandler_Unhandled) BOOST_REQUIRE_EQUAL(h["Status"], "500 TestIceSpider::Ex"); BOOST_REQUIRE_EQUAL(h["Content-Type"], "text/plain"); auto & o = requestDeleteItem.output; - auto b = o.str().substr(o.tellg()); + auto b = o.str().substr(static_cast(o.tellg())); BOOST_REQUIRE_EQUAL(b, "Exception type: TestIceSpider::Ex\nDetail: test error\n"); } -- cgit v1.2.3