Commit b47702ee authored by Dominik Charousset's avatar Dominik Charousset

Fix minor warnings found via cppcheck

parent fd9a200d
......@@ -48,11 +48,10 @@ struct uniform_value_t {
void* val;
virtual uniform_value copy() = 0;
virtual ~uniform_value_t();
};
template <class T, class... Ts>
uniform_value make_uniform_value(const uniform_type_info* ti, Ts&&... args) {
uniform_value make_uniform_value(const uniform_type_info* uti, Ts&&... args) {
struct container : uniform_value_t {
T value;
container(const uniform_type_info* ptr, T arg) : value(std::move(arg)) {
......@@ -62,9 +61,8 @@ uniform_value make_uniform_value(const uniform_type_info* ti, Ts&&... args) {
uniform_value copy() override {
return uniform_value{new container(ti, value)};
}
};
return uniform_value{new container(ti, T(std::forward<Ts>(args)...))};
return uniform_value{new container(uti, T(std::forward<Ts>(args)...))};
}
/**
......@@ -276,12 +274,10 @@ class uniform_type_info {
uint16_t m_type_nr;
};
using uniform_type_info_ptr = std::unique_ptr<uniform_type_info>;
/**
* @relates uniform_type_info
*/
using uniform_type_info_ptr = std::unique_ptr<uniform_type_info>;
/**
* @relates uniform_type_info
......
......@@ -180,7 +180,7 @@ constexpr size_t max_iterations = 3;
struct c_free {
template <class T>
void operator()(T* ptr) {
void operator()(T* ptr) const {
free(ptr);
}
};
......
......@@ -204,7 +204,7 @@ message_id local_actor::sync_send_impl(message_priority mp,
return nri.response_id();
}
//<backward_compatibility version="0.12">
// <backward_compatibility version="0.12">
message& local_actor::last_dequeued() {
if (!m_current_element) {
auto errstr = "last_dequeued called after forward_to or not in a callback";
......@@ -222,6 +222,6 @@ actor_addr& local_actor::last_sender() {
}
return m_current_element->sender;
}
//</backward_compatibility>
// </backward_compatibility>
} // namespace caf
......@@ -338,8 +338,9 @@ class string_deserializer : public deserializer, public dummy_backend {
// and ':' must be ignored
consume(':');
}
auto str_end = m_str.end();
string::iterator substr_end;
auto find_if_cond = [](char c)->bool {
auto find_if_pred = [](char c) -> bool {
switch (c) {
case ')':
case '}':
......@@ -351,70 +352,61 @@ class string_deserializer : public deserializer, public dummy_backend {
return false;
}
};
if (get<string>(&storage) || get<atom_value>(&storage)) {
char needle = (get<string>(&storage)) ? '"' : '\'';
if (*m_pos == needle) {
// skip leading "
++m_pos;
char last_char = needle;
auto find_if_str_cond = [&last_char, needle ](char c)->bool {
if (c == needle && last_char != '\\') {
return true;
if (get<string>(&storage) || get<atom_value>(&storage)) {
if (*m_pos != needle) {
throw std::runtime_error("expected opening quotation mark");
}
last_char = c;
return false;
auto pred = [needle](char prev, char curr) {
return prev != '\\' && curr == needle;
};
substr_end = find_if(m_pos, m_str.end(), find_if_str_cond);
} else {
substr_end = find_if(m_pos, m_str.end(), find_if_cond);
substr_end = std::adjacent_find(m_pos, str_end, pred);
if (substr_end != str_end) {
++m_pos; // skip opening quote
++substr_end; // set iterator to position of closing quote
}
} else {
substr_end = find_if(m_pos, m_str.end(), find_if_cond);
substr_end = find_if(m_pos, str_end, find_if_pred);
}
if (substr_end == m_str.end()) {
if (substr_end == str_end) {
throw std::runtime_error("malformed string (unterminated value)");
}
string substr(m_pos, substr_end);
m_pos += static_cast<difference_type>(substr.size());
if (get<string>(&storage) || get<atom_value>(&storage)) {
char needle = (get<string>(&storage)) ? '"' : '\'';
// skip trailing "
if (*m_pos != needle) {
if (m_pos == str_end || *m_pos != needle) {
string error_msg;
error_msg = "malformed string, expected '";
error_msg += needle;
error_msg += "' found '";
if (m_pos == str_end) {
error_msg += "-end of string-";
} else {
error_msg += *m_pos;
}
error_msg += "'";
throw std::runtime_error(error_msg);
}
++m_pos;
// replace '\"' by '"'
char last_char = ' ';
auto cond = [&last_char, needle ](char c)->bool {
if (c == needle && last_char == '\\') {
return true;
}
last_char = c;
return false;
auto pred = [needle](char prev, char curr) {
return prev == '\\' && curr == needle;
};
string tmp;
auto sbegin = substr.begin();
auto send = substr.end();
for (auto i = find_if(sbegin, send, cond); i != send;
i = find_if(i, send, cond)) {
--i;
tmp.append(sbegin, i);
auto prev = substr.begin();
auto last = substr.end();
do {
auto i = std::adjacent_find(prev, last, pred);
tmp.append(prev, i);
if (i == last) {
prev = last;
} else {
tmp += needle;
i += 2;
sbegin = i;
}
if (sbegin != substr.begin()) {
tmp.append(sbegin, send);
}
if (!tmp.empty()) {
substr = std::move(tmp);
prev = i + 2;
}
} while (prev != last);
substr.swap(tmp);
}
from_string_reader fsr(substr);
apply_visitor(fsr, storage);
......
......@@ -69,7 +69,7 @@ class set_commit_rollback {
inline void inc() {
++m_pos;
}
inline pointer current() {
inline pointer current() const {
return &m_data[m_pos];
}
inline void commit() {
......
......@@ -204,12 +204,8 @@ namespace network {
a.inaddr.sin_family = AF_INET;
a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
a.inaddr.sin_port = 0;
bool success = false;
// makes sure all sockets are closed in case of an error
auto guard = detail::make_scope_guard([&] {
if (success) {
return; // everyhting's fine
}
auto e = WSAGetLastError();
closesocket(listener);
closesocket(socks[0]);
......@@ -242,7 +238,7 @@ namespace network {
auto write_fd = ccall(cc_valid_socket, "accept() failed",
accept, listener, NULL, NULL);
closesocket(listener);
success = true;
guard.disable();
return {read_fd, write_fd};
}
......
......@@ -118,6 +118,19 @@ enum class test_enum {
} // namespace <anonymous>
void test_string_serialization() {
auto input = make_message("hello \"actor world\"!", atom("foo"));
auto s = to_string(input);
CAF_CHECK_EQUAL(s, R"#(@<>+@str+@atom ( "hello \"actor world\"!", 'foo' ))#");
auto m = from_string<message>(s);
if (!m) {
CAF_PRINTERR("from_string failed");
return;
}
CAF_CHECK(*m == input);
CAF_CHECK_EQUAL(to_string(*m), to_string(input));
}
int main() {
CAF_TEST(test_serialization);
......@@ -144,6 +157,8 @@ int main() {
CAF_CHECK_EQUAL(to_string(nid), to_string(*nid2));
}
test_string_serialization();
/*
auto oarr = new detail::object_array;
oarr->push_back(object::from(static_cast<uint32_t>(42)));
......
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