diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-09-09 19:33:38 +0100 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-12-17 15:36:04 +0000 | 
| commit | c8d8139e6dc5e1290015080e3b36dee22090a7cf (patch) | |
| tree | 302dbac2a61ad05c97c53990e723bc32fedfc30c | |
| parent | Add -Wold-style-cast (diff) | |
| download | icespider-c8d8139e6dc5e1290015080e3b36dee22090a7cf.tar.bz2 icespider-c8d8139e6dc5e1290015080e3b36dee22090a7cf.tar.xz icespider-c8d8139e6dc5e1290015080e3b36dee22090a7cf.zip  | |
Add -Wconversion and -Wsign-conversion
| -rw-r--r-- | Jamroot.jam | 2 | ||||
| -rw-r--r-- | icespider/common/pathparts.cpp | 4 | ||||
| -rw-r--r-- | icespider/common/pathparts.h | 2 | ||||
| -rw-r--r-- | icespider/compile/routeCompiler.cpp | 2 | ||||
| -rw-r--r-- | icespider/core/ihttpRequest.cpp | 4 | ||||
| -rw-r--r-- | icespider/core/xwwwFormUrlEncoded.cpp | 20 | ||||
| -rw-r--r-- | icespider/fileSessions/fileSessions.cpp | 8 | ||||
| -rw-r--r-- | 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  			<variant>debug:<cflags>-Wcast-align  			<variant>debug:<cflags>-Wunused  			<variant>debug:<cflags>-Woverloaded-virtual +			<variant>debug:<cflags>-Wconversion +			<variant>debug:<cflags>-Wsign-conversion  			<variant>debug:<cflags>-Wnull-dereference  			<variant>debug:<cflags>-Wdouble-promotion  			<variant>debug:<cflags>-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<PathParameter>(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<PathParameter *>(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::size_t>(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<char, char>;  using HexOut = std::array<HexPair, CHARMAX>;  constexpr auto hexout = []() {  	auto hexchar = [](auto c) { -		return c < 10 ? '0' + c : 'a' - 10 + c; +		return static_cast<char>(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<std::optional<unsigned char>, CHARMAX> hextable = []() {  	std::array<std::optional<unsigned char>, 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<std::array<char, CHARMAX>, 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<char>((*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<uint8_t>(*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::string::size_type>(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::string::size_type>(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<uint8_t>(*(i + 1))][static_cast<uint8_t>(*(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<Ice::Short>(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<size_t>(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<std::string::size_type>(o.tellg()));  	BOOST_REQUIRE_EQUAL(b, "Exception type: TestIceSpider::Ex\nDetail: test error\n");  }  | 
