Fixes #149: added and resolved -Wsign-conversion warnings
This commit is contained in:
parent
ea2b0f4a80
commit
64bd58e5da
6 changed files with 19 additions and 19 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 2.8.8)
|
cmake_minimum_required (VERSION 2.8.8)
|
||||||
project (Simple-Web-Server)
|
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(.)
|
include_directories(.)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -534,16 +534,16 @@ namespace SimpleWeb {
|
||||||
getline(session->response->content, line);
|
getline(session->response->content, line);
|
||||||
bytes_transferred -= line.size() + 1;
|
bytes_transferred -= line.size() + 1;
|
||||||
line.pop_back();
|
line.pop_back();
|
||||||
std::streamsize length = stol(line, 0, 16);
|
auto length = stoul(line, 0, 16);
|
||||||
|
|
||||||
auto num_additional_bytes = static_cast<std::streamsize>(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]() {
|
auto post_process = [this, session, tmp_streambuf, length]() {
|
||||||
std::ostream tmp_stream(tmp_streambuf.get());
|
std::ostream tmp_stream(tmp_streambuf.get());
|
||||||
if(length > 0) {
|
if(length > 0) {
|
||||||
std::vector<char> buffer(static_cast<size_t>(length));
|
std::vector<char> buffer(static_cast<size_t>(length));
|
||||||
session->response->content.read(&buffer[0], length);
|
session->response->content.read(&buffer[0], static_cast<std::streamsize>(length));
|
||||||
tmp_stream.write(&buffer[0], length);
|
tmp_stream.write(&buffer[0], static_cast<std::streamsize>(length));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove "\r\n"
|
// Remove "\r\n"
|
||||||
|
|
|
||||||
16
crypto.hpp
16
crypto.hpp
|
|
@ -40,7 +40,7 @@ namespace SimpleWeb {
|
||||||
BIO_set_mem_buf(b64, bptr, BIO_CLOSE);
|
BIO_set_mem_buf(b64, bptr, BIO_CLOSE);
|
||||||
|
|
||||||
// Write directly to base64-buffer to avoid copy
|
// Write directly to base64-buffer to avoid copy
|
||||||
int base64_length = static_cast<int>(round(4 * ceil(static_cast<double>(ascii.size()) / 3.0)));
|
auto base64_length = static_cast<size_t>(round(4 * ceil(static_cast<double>(ascii.size()) / 3.0)));
|
||||||
base64.resize(base64_length);
|
base64.resize(base64_length);
|
||||||
bptr->length = 0;
|
bptr->length = 0;
|
||||||
bptr->max = base64_length + 1;
|
bptr->max = base64_length + 1;
|
||||||
|
|
@ -71,9 +71,9 @@ namespace SimpleWeb {
|
||||||
bio = BIO_new_mem_buf(&base64[0], static_cast<int>(base64.size()));
|
bio = BIO_new_mem_buf(&base64[0], static_cast<int>(base64.size()));
|
||||||
bio = BIO_push(b64, bio);
|
bio = BIO_push(b64, bio);
|
||||||
|
|
||||||
int decoded_length = BIO_read(bio, &ascii[0], static_cast<int>(ascii.size()));
|
auto decoded_length = BIO_read(bio, &ascii[0], static_cast<int>(ascii.size()));
|
||||||
if(decoded_length > 0)
|
if(decoded_length > 0)
|
||||||
ascii.resize(decoded_length);
|
ascii.resize(static_cast<size_t>(decoded_length));
|
||||||
else
|
else
|
||||||
ascii.clear();
|
ascii.clear();
|
||||||
|
|
||||||
|
|
@ -110,7 +110,7 @@ namespace SimpleWeb {
|
||||||
std::streamsize read_length;
|
std::streamsize read_length;
|
||||||
std::vector<char> buffer(buffer_size);
|
std::vector<char> buffer(buffer_size);
|
||||||
while((read_length = stream.read(&buffer[0], buffer_size).gcount()) > 0)
|
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<size_t>(read_length));
|
||||||
std::string hash;
|
std::string hash;
|
||||||
hash.resize(128 / 8);
|
hash.resize(128 / 8);
|
||||||
MD5_Final(reinterpret_cast<unsigned char *>(&hash[0]), &context);
|
MD5_Final(reinterpret_cast<unsigned char *>(&hash[0]), &context);
|
||||||
|
|
@ -139,7 +139,7 @@ namespace SimpleWeb {
|
||||||
std::streamsize read_length;
|
std::streamsize read_length;
|
||||||
std::vector<char> buffer(buffer_size);
|
std::vector<char> buffer(buffer_size);
|
||||||
while((read_length = stream.read(&buffer[0], buffer_size).gcount()) > 0)
|
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<size_t>(read_length));
|
||||||
std::string hash;
|
std::string hash;
|
||||||
hash.resize(160 / 8);
|
hash.resize(160 / 8);
|
||||||
SHA1_Final(reinterpret_cast<unsigned char *>(&hash[0]), &context);
|
SHA1_Final(reinterpret_cast<unsigned char *>(&hash[0]), &context);
|
||||||
|
|
@ -168,7 +168,7 @@ namespace SimpleWeb {
|
||||||
std::streamsize read_length;
|
std::streamsize read_length;
|
||||||
std::vector<char> buffer(buffer_size);
|
std::vector<char> buffer(buffer_size);
|
||||||
while((read_length = stream.read(&buffer[0], buffer_size).gcount()) > 0)
|
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<size_t>(read_length));
|
||||||
std::string hash;
|
std::string hash;
|
||||||
hash.resize(256 / 8);
|
hash.resize(256 / 8);
|
||||||
SHA256_Final(reinterpret_cast<unsigned char *>(&hash[0]), &context);
|
SHA256_Final(reinterpret_cast<unsigned char *>(&hash[0]), &context);
|
||||||
|
|
@ -197,7 +197,7 @@ namespace SimpleWeb {
|
||||||
std::streamsize read_length;
|
std::streamsize read_length;
|
||||||
std::vector<char> buffer(buffer_size);
|
std::vector<char> buffer(buffer_size);
|
||||||
while((read_length = stream.read(&buffer[0], buffer_size).gcount()) > 0)
|
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<size_t>(read_length));
|
||||||
std::string hash;
|
std::string hash;
|
||||||
hash.resize(512 / 8);
|
hash.resize(512 / 8);
|
||||||
SHA512_Final(reinterpret_cast<unsigned char *>(&hash[0]), &context);
|
SHA512_Final(reinterpret_cast<unsigned char *>(&hash[0]), &context);
|
||||||
|
|
@ -211,7 +211,7 @@ namespace SimpleWeb {
|
||||||
/// key_size is number of bytes of the returned key.
|
/// 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 {
|
static std::string pbkdf2(const std::string &password, const std::string &salt, int iterations, int key_size) noexcept {
|
||||||
std::string key;
|
std::string key;
|
||||||
key.resize(key_size);
|
key.resize(static_cast<size_t>(key_size));
|
||||||
PKCS5_PBKDF2_HMAC_SHA1(password.c_str(), password.size(),
|
PKCS5_PBKDF2_HMAC_SHA1(password.c_str(), password.size(),
|
||||||
reinterpret_cast<const unsigned char *>(salt.c_str()), salt.size(), iterations,
|
reinterpret_cast<const unsigned char *>(salt.c_str()), salt.size(), iterations,
|
||||||
key_size, reinterpret_cast<unsigned char *>(&key[0]));
|
key_size, reinterpret_cast<unsigned char *>(&key[0]));
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ int main() {
|
||||||
// Read and send 128 KB at a time
|
// Read and send 128 KB at a time
|
||||||
static vector<char> buffer(131072); // Safe when server is running on one thread
|
static vector<char> buffer(131072); // Safe when server is running on one thread
|
||||||
streamsize read_length;
|
streamsize read_length;
|
||||||
if((read_length = ifs->read(&buffer[0], buffer.size()).gcount()) > 0) {
|
if((read_length = ifs->read(&buffer[0], static_cast<streamsize>(buffer.size())).gcount()) > 0) {
|
||||||
response->write(&buffer[0], read_length);
|
response->write(&buffer[0], read_length);
|
||||||
if(read_length == static_cast<streamsize>(buffer.size())) {
|
if(read_length == static_cast<streamsize>(buffer.size())) {
|
||||||
response->send([response, ifs](const SimpleWeb::error_code &ec) {
|
response->send([response, ifs](const SimpleWeb::error_code &ec) {
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ int main() {
|
||||||
// Read and send 128 KB at a time
|
// Read and send 128 KB at a time
|
||||||
static vector<char> buffer(131072); // Safe when server is running on one thread
|
static vector<char> buffer(131072); // Safe when server is running on one thread
|
||||||
streamsize read_length;
|
streamsize read_length;
|
||||||
if((read_length = ifs->read(&buffer[0], buffer.size()).gcount()) > 0) {
|
if((read_length = ifs->read(&buffer[0], static_cast<streamsize>(buffer.size())).gcount()) > 0) {
|
||||||
response->write(&buffer[0], read_length);
|
response->write(&buffer[0], read_length);
|
||||||
if(read_length == static_cast<streamsize>(buffer.size())) {
|
if(read_length == static_cast<streamsize>(buffer.size())) {
|
||||||
response->send([response, ifs](const SimpleWeb::error_code &ec) {
|
response->send([response, ifs](const SimpleWeb::error_code &ec) {
|
||||||
|
|
|
||||||
|
|
@ -104,8 +104,8 @@ namespace SimpleWeb {
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
size_t name_pos = 0;
|
size_t name_pos = 0;
|
||||||
size_t name_end_pos = -1;
|
size_t name_end_pos = static_cast<size_t>(-1);
|
||||||
size_t value_pos = -1;
|
size_t value_pos = static_cast<size_t>(-1);
|
||||||
for(size_t c = 0; c < query_string.size(); ++c) {
|
for(size_t c = 0; c < query_string.size(); ++c) {
|
||||||
if(query_string[c] == '&') {
|
if(query_string[c] == '&') {
|
||||||
auto name = query_string.substr(name_pos, (name_end_pos == std::string::npos ? c : name_end_pos) - name_pos);
|
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));
|
result.emplace(std::move(name), Percent::decode(value));
|
||||||
}
|
}
|
||||||
name_pos = c + 1;
|
name_pos = c + 1;
|
||||||
name_end_pos = -1;
|
name_end_pos = static_cast<size_t>(-1);
|
||||||
value_pos = -1;
|
value_pos = static_cast<size_t>(-1);
|
||||||
}
|
}
|
||||||
else if(query_string[c] == '=') {
|
else if(query_string[c] == '=') {
|
||||||
name_end_pos = c;
|
name_end_pos = c;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue