From 64bd58e5da4b5166c390d41f988d508af44ebed9 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sat, 12 Aug 2017 15:28:35 +0200 Subject: [PATCH] Fixes #149: added and resolved -Wsign-conversion warnings --- CMakeLists.txt | 2 +- client_http.hpp | 8 ++++---- crypto.hpp | 16 ++++++++-------- http_examples.cpp | 2 +- https_examples.cpp | 2 +- utility.hpp | 8 ++++---- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 075e4d4..950bd82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 2.8.8) project (Simple-Web-Server) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wsign-conversion") include_directories(.) diff --git a/client_http.hpp b/client_http.hpp index 559bbc9..ef6fba9 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -534,16 +534,16 @@ namespace SimpleWeb { getline(session->response->content, line); bytes_transferred -= line.size() + 1; line.pop_back(); - std::streamsize length = stol(line, 0, 16); + auto length = stoul(line, 0, 16); - auto num_additional_bytes = static_cast(session->response->content_buffer.size() - bytes_transferred); + auto num_additional_bytes = session->response->content_buffer.size() - bytes_transferred; auto post_process = [this, session, tmp_streambuf, length]() { std::ostream tmp_stream(tmp_streambuf.get()); if(length > 0) { std::vector buffer(static_cast(length)); - session->response->content.read(&buffer[0], length); - tmp_stream.write(&buffer[0], length); + session->response->content.read(&buffer[0], static_cast(length)); + tmp_stream.write(&buffer[0], static_cast(length)); } // Remove "\r\n" diff --git a/crypto.hpp b/crypto.hpp index c57d2c8..697d8f3 100644 --- a/crypto.hpp +++ b/crypto.hpp @@ -40,7 +40,7 @@ namespace SimpleWeb { BIO_set_mem_buf(b64, bptr, BIO_CLOSE); // Write directly to base64-buffer to avoid copy - int base64_length = static_cast(round(4 * ceil(static_cast(ascii.size()) / 3.0))); + auto base64_length = static_cast(round(4 * ceil(static_cast(ascii.size()) / 3.0))); base64.resize(base64_length); bptr->length = 0; bptr->max = base64_length + 1; @@ -71,9 +71,9 @@ namespace SimpleWeb { bio = BIO_new_mem_buf(&base64[0], static_cast(base64.size())); bio = BIO_push(b64, bio); - int decoded_length = BIO_read(bio, &ascii[0], static_cast(ascii.size())); + auto decoded_length = BIO_read(bio, &ascii[0], static_cast(ascii.size())); if(decoded_length > 0) - ascii.resize(decoded_length); + ascii.resize(static_cast(decoded_length)); else ascii.clear(); @@ -110,7 +110,7 @@ namespace SimpleWeb { std::streamsize read_length; std::vector buffer(buffer_size); while((read_length = stream.read(&buffer[0], buffer_size).gcount()) > 0) - MD5_Update(&context, buffer.data(), read_length); + MD5_Update(&context, buffer.data(), static_cast(read_length)); std::string hash; hash.resize(128 / 8); MD5_Final(reinterpret_cast(&hash[0]), &context); @@ -139,7 +139,7 @@ namespace SimpleWeb { std::streamsize read_length; std::vector buffer(buffer_size); while((read_length = stream.read(&buffer[0], buffer_size).gcount()) > 0) - SHA1_Update(&context, buffer.data(), read_length); + SHA1_Update(&context, buffer.data(), static_cast(read_length)); std::string hash; hash.resize(160 / 8); SHA1_Final(reinterpret_cast(&hash[0]), &context); @@ -168,7 +168,7 @@ namespace SimpleWeb { std::streamsize read_length; std::vector buffer(buffer_size); while((read_length = stream.read(&buffer[0], buffer_size).gcount()) > 0) - SHA256_Update(&context, buffer.data(), read_length); + SHA256_Update(&context, buffer.data(), static_cast(read_length)); std::string hash; hash.resize(256 / 8); SHA256_Final(reinterpret_cast(&hash[0]), &context); @@ -197,7 +197,7 @@ namespace SimpleWeb { std::streamsize read_length; std::vector buffer(buffer_size); while((read_length = stream.read(&buffer[0], buffer_size).gcount()) > 0) - SHA512_Update(&context, buffer.data(), read_length); + SHA512_Update(&context, buffer.data(), static_cast(read_length)); std::string hash; hash.resize(512 / 8); SHA512_Final(reinterpret_cast(&hash[0]), &context); @@ -211,7 +211,7 @@ namespace SimpleWeb { /// key_size is number of bytes of the returned key. static std::string pbkdf2(const std::string &password, const std::string &salt, int iterations, int key_size) noexcept { std::string key; - key.resize(key_size); + key.resize(static_cast(key_size)); PKCS5_PBKDF2_HMAC_SHA1(password.c_str(), password.size(), reinterpret_cast(salt.c_str()), salt.size(), iterations, key_size, reinterpret_cast(&key[0])); diff --git a/http_examples.cpp b/http_examples.cpp index 8b0bb06..47304dc 100644 --- a/http_examples.cpp +++ b/http_examples.cpp @@ -188,7 +188,7 @@ int main() { // Read and send 128 KB at a time static vector buffer(131072); // Safe when server is running on one thread streamsize read_length; - if((read_length = ifs->read(&buffer[0], buffer.size()).gcount()) > 0) { + if((read_length = ifs->read(&buffer[0], static_cast(buffer.size())).gcount()) > 0) { response->write(&buffer[0], read_length); if(read_length == static_cast(buffer.size())) { response->send([response, ifs](const SimpleWeb::error_code &ec) { diff --git a/https_examples.cpp b/https_examples.cpp index f5d6ba6..6f15263 100644 --- a/https_examples.cpp +++ b/https_examples.cpp @@ -186,7 +186,7 @@ int main() { // Read and send 128 KB at a time static vector buffer(131072); // Safe when server is running on one thread streamsize read_length; - if((read_length = ifs->read(&buffer[0], buffer.size()).gcount()) > 0) { + if((read_length = ifs->read(&buffer[0], static_cast(buffer.size())).gcount()) > 0) { response->write(&buffer[0], read_length); if(read_length == static_cast(buffer.size())) { response->send([response, ifs](const SimpleWeb::error_code &ec) { diff --git a/utility.hpp b/utility.hpp index 7531bfb..4a58814 100644 --- a/utility.hpp +++ b/utility.hpp @@ -104,8 +104,8 @@ namespace SimpleWeb { return result; size_t name_pos = 0; - size_t name_end_pos = -1; - size_t value_pos = -1; + size_t name_end_pos = static_cast(-1); + size_t value_pos = static_cast(-1); for(size_t c = 0; c < query_string.size(); ++c) { if(query_string[c] == '&') { auto name = query_string.substr(name_pos, (name_end_pos == std::string::npos ? c : name_end_pos) - name_pos); @@ -114,8 +114,8 @@ namespace SimpleWeb { result.emplace(std::move(name), Percent::decode(value)); } name_pos = c + 1; - name_end_pos = -1; - value_pos = -1; + name_end_pos = static_cast(-1); + value_pos = static_cast(-1); } else if(query_string[c] == '=') { name_end_pos = c;