Commit 6fee6f74 authored by Dominik Charousset's avatar Dominik Charousset

Use correct C++ casts

parent 154e464d
...@@ -69,8 +69,10 @@ using dword = uint32_t; ...@@ -69,8 +69,10 @@ using dword = uint32_t;
// collect four bytes into one word: // collect four bytes into one word:
#define BYTES_TO_DWORD(strptr) \ #define BYTES_TO_DWORD(strptr) \
(((dword) * ((strptr) + 3) << 24) | ((dword) * ((strptr) + 2) << 16) \ ((static_cast<dword>(*((strptr) + 3)) << 24) \
| ((dword) * ((strptr) + 1) << 8) | ((dword) * (strptr))) | (static_cast<dword>(*((strptr) + 2)) << 16) \
| (static_cast<dword>(*((strptr) + 1)) << 8) \
| (static_cast<dword>(*(strptr))))
// ROL(x, n) cyclically rotates x over n bits to the left // ROL(x, n) cyclically rotates x over n bits to the left
// x must be of an unsigned 32 bits type and 0 <= n < 32. // x must be of an unsigned 32 bits type and 0 <= n < 32.
...@@ -360,10 +362,10 @@ void MDfinish(dword* MDbuf, const byte* strptr, dword lswlen, dword mswlen) { ...@@ -360,10 +362,10 @@ void MDfinish(dword* MDbuf, const byte* strptr, dword lswlen, dword mswlen) {
// put bytes from strptr into X // put bytes from strptr into X
for (unsigned int i = 0; i < (lswlen & 63); ++i) { for (unsigned int i = 0; i < (lswlen & 63); ++i) {
// byte i goes into word X[i div 4] at pos. 8*(i mod 4) // byte i goes into word X[i div 4] at pos. 8*(i mod 4)
X[i >> 2] ^= (dword) * strptr++ << (8 * (i & 3)); X[i >> 2] ^= static_cast<dword>(*strptr++) << (8 * (i & 3));
} }
// append the bit m_n == 1 // append the bit m_n == 1
X[(lswlen >> 2) & 15] ^= (dword)1 << (8 * (lswlen & 3) + 7); X[(lswlen >> 2) & 15] ^= static_cast<dword>(1) << (8 * (lswlen & 3) + 7);
if ((lswlen & 63) > 55) { if ((lswlen & 63) > 55) {
// length goes to next block // length goes to next block
compress(MDbuf, X); compress(MDbuf, X);
......
...@@ -268,7 +268,7 @@ class broker : public extend<local_actor>:: ...@@ -268,7 +268,7 @@ class broker : public extend<local_actor>::
static broker_ptr from(F fun) { static broker_ptr from(F fun) {
// transform to STD function here, because GCC is unable // transform to STD function here, because GCC is unable
// to select proper overload otherwise ... // to select proper overload otherwise ...
using fres = decltype(fun((broker*)nullptr)); using fres = decltype(fun(static_cast<broker*>(nullptr)));
std::function<fres(broker*)> stdfun{std::move(fun)}; std::function<fres(broker*)> stdfun{std::move(fun)};
return from_impl(std::move(stdfun)); return from_impl(std::move(stdfun));
} }
......
...@@ -478,7 +478,7 @@ namespace network { ...@@ -478,7 +478,7 @@ namespace network {
} else { } else {
// update event mask of existing entry // update event mask of existing entry
CAF_REQUIRE(*j == e.ptr); CAF_REQUIRE(*j == e.ptr);
i->events = e.mask; i->events = static_cast<short>(e.mask);
} }
if (e.ptr) { if (e.ptr) {
auto remove_from_loop_if_needed = [&](int flag, operation flag_op) { auto remove_from_loop_if_needed = [&](int flag, operation flag_op) {
...@@ -503,7 +503,7 @@ int add_flag(operation op, int bf) { ...@@ -503,7 +503,7 @@ int add_flag(operation op, int bf) {
return bf | input_mask; return bf | input_mask;
case operation::write: case operation::write:
return bf | output_mask; return bf | output_mask;
default: case operation::propagate_error:
CAF_LOGF_ERROR("unexpected operation"); CAF_LOGF_ERROR("unexpected operation");
break; break;
} }
...@@ -517,7 +517,7 @@ int del_flag(operation op, int bf) { ...@@ -517,7 +517,7 @@ int del_flag(operation op, int bf) {
return bf & ~input_mask; return bf & ~input_mask;
case operation::write: case operation::write:
return bf & ~output_mask; return bf & ~output_mask;
default: case operation::propagate_error:
CAF_LOGF_ERROR("unexpected operation"); CAF_LOGF_ERROR("unexpected operation");
break; break;
} }
...@@ -926,7 +926,8 @@ native_socket new_ipv4_connection_impl(const std::string& host, uint16_t port) { ...@@ -926,7 +926,8 @@ native_socket new_ipv4_connection_impl(const std::string& host, uint16_t port) {
static_cast<size_t>(server->h_length)); static_cast<size_t>(server->h_length));
serv_addr.sin_port = htons(port); serv_addr.sin_port = htons(port);
CAF_LOGF_DEBUG("call connect()"); CAF_LOGF_DEBUG("call connect()");
if (connect(fd, (const sockaddr*)&serv_addr, sizeof(serv_addr)) != 0) { if (connect(fd, reinterpret_cast<const sockaddr*>(&serv_addr),
sizeof(serv_addr)) != 0) {
CAF_LOGF_ERROR("could not connect to to " << host << " on port " << port); CAF_LOGF_ERROR("could not connect to to " << host << " on port " << port);
throw network_error("could not connect to host"); throw network_error("could not connect to host");
} }
...@@ -958,7 +959,7 @@ native_socket new_ipv4_acceptor_impl(uint16_t port, const char* addr) { ...@@ -958,7 +959,7 @@ native_socket new_ipv4_acceptor_impl(uint16_t port, const char* addr) {
throw_io_failure("unable to set SO_REUSEADDR"); throw_io_failure("unable to set SO_REUSEADDR");
} }
struct sockaddr_in serv_addr; struct sockaddr_in serv_addr;
memset((char*)&serv_addr, 0, sizeof(serv_addr)); memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
if (!addr) { if (!addr) {
serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_addr.s_addr = INADDR_ANY;
...@@ -966,7 +967,8 @@ native_socket new_ipv4_acceptor_impl(uint16_t port, const char* addr) { ...@@ -966,7 +967,8 @@ native_socket new_ipv4_acceptor_impl(uint16_t port, const char* addr) {
throw network_error("invalid IPv4 address"); throw network_error("invalid IPv4 address");
} }
serv_addr.sin_port = htons(port); serv_addr.sin_port = htons(port);
if (bind(fd, (sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { if (bind(fd, reinterpret_cast<sockaddr*>(&serv_addr),
sizeof(serv_addr)) < 0) {
throw bind_failure(last_socket_error_as_string()); throw bind_failure(last_socket_error_as_string());
} }
if (listen(fd, SOMAXCONN) != 0) { if (listen(fd, SOMAXCONN) != 0) {
......
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