Commit 8b45b58f authored by Dominik Charousset's avatar Dominik Charousset

Fix conversion warnings

parent b35e41a8
......@@ -8,8 +8,8 @@
* - ./build/bin/group_chat -g remote:chatroom@localhost:4242 -n bob *
\ ******************************************************************************/
#include <cstdlib>
#include <string>
#include <cstdlib>
#include <iostream>
#include "caf/all.hpp"
......@@ -20,9 +20,9 @@ using namespace caf;
optional<uint16_t> to_port(const string& arg) {
char* last = nullptr;
auto res = strtol(arg.c_str(), &last, 10);
if (last == (arg.c_str() + arg.size()) && res > 1024) {
return res;
auto res = strtoul(arg.c_str(), &last, 10);
if (last == (arg.c_str() + arg.size()) && res <= 65536) {
return static_cast<uint16_t>(res);
}
return none;
}
......
......@@ -336,7 +336,7 @@ class single_reader_queue {
pointer reader_blocked_dummy() {
// we are not going to dereference this pointer either
return reinterpret_cast<pointer>(reinterpret_cast<intptr_t>(this)
+ sizeof(void*));
+ static_cast<intptr_t>(sizeof(void*)));
}
bool is_dummy(pointer ptr) {
......
......@@ -72,21 +72,22 @@ void splice(std::string& str, const std::string& glue, T&& arg, Ts&&... args) {
splice(str, glue, std::forward<Ts>(args)...);
}
template <size_t WhatSize, size_t WithSize>
template <ptrdiff_t WhatSize, ptrdiff_t WithSize>
void replace_all(std::string& str,
const char (&what)[WhatSize],
const char (&with)[WithSize]) {
// end(what) - 1 points to the null-terminator
auto next = [&](std::string::iterator pos) -> std::string::iterator{
auto next = [&](std::string::iterator pos) -> std::string::iterator {
return std::search(pos, str.end(), std::begin(what), std::end(what) - 1);
};
auto i = next(std::begin(str));
while (i != std::end(str)) {
auto before = static_cast<size_t>(std::distance(std::begin(str), i));
auto before = std::distance(std::begin(str), i);
CAF_REQUIRE(before >= 0);
str.replace(i, i + WhatSize - 1, with);
// i became invalidated -> use new iterator pointing
// to the first character after the replaced text
i = next(std::begin(str) + before + (WithSize - 1));
i = next(str.begin() + before + (WithSize - 1));
}
}
......
......@@ -41,7 +41,8 @@ using string_proj = std::function<optional<std::string> (const std::string&)>;
inline string_proj extract_longopt_arg(const std::string& prefix) {
return [prefix](const std::string& arg) -> optional<std::string> {
if (arg.compare(0, prefix.size(), prefix) == 0) {
return std::string(arg.begin() + prefix.size(), arg.end());
return std::string(arg.begin() + static_cast<ptrdiff_t>(prefix.size()),
arg.end());
}
return none;
};
......
......@@ -263,7 +263,7 @@ void basp_broker::dispatch(const actor_addr& from, const actor_addr& to,
}
auto& buf = wr_buf(route.hdl);
// reserve space in the buffer to write the broker message later on
auto wr_pos = buf.size();
auto wr_pos = static_cast<ptrdiff_t>(buf.size());
char placeholder[basp::header_size];
buf.insert(buf.end(), std::begin(placeholder), std::end(placeholder));
auto before = buf.size();
......@@ -639,7 +639,7 @@ void basp_broker::init_handshake_as_sever(connection_context& ctx,
CAF_LOG_TRACE(CAF_ARG(this));
CAF_REQUIRE(node() != invalid_node_id);
auto& buf = wr_buf(ctx.hdl);
auto wrpos = buf.size();
auto wrpos = static_cast<ptrdiff_t>(buf.size());
char padding[basp::header_size];
buf.insert(buf.end(), std::begin(padding), std::end(padding));
auto before = buf.size();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment