Commit c13c4b7b authored by Dominik Charousset's avatar Dominik Charousset

Fix handling of char pointers in deep_to_string

parent d6bc6cc6
......@@ -30,6 +30,11 @@ is based on [Keep a Changelog](https://keepachangelog.com).
- CAF 0.18 added support for `make_behavior` in state classes. However, CAF
erroneously picked this member function over running the function body when
spawning function-based actors (#1149).
- When passing `nullptr` or custom types with implicit conversions to
`const char*` to `deep_to_string`, CAF could run into a segfault in the former
case or do unexpected things in the latter case. The stringification inspector
now matches precisely on pointer types to stop the compiler from doing
implicit conversions in the first place.
## [0.18.0-rc.1] - 2020-09-09
......
......@@ -19,6 +19,7 @@
#pragma once
#include <chrono>
#include <cstring>
#include <string>
#include <type_traits>
#include <vector>
......@@ -174,18 +175,20 @@ public:
return true;
}
bool builtin_inspect(const char* x);
template <class T>
bool builtin_inspect(const T* x) {
sep();
if (!x) {
if (x == nullptr) {
sep();
result_ += "null";
return true;
} else if constexpr (std::is_same<T, char>::value) {
return value(string_view{x, strlen(x)});
} else {
sep();
result_ += '*';
save_value(*this, detail::as_mutable_ref(*x));
return true;
}
return true;
}
template <class T>
......
......@@ -235,10 +235,6 @@ bool stringification_inspector::value(const std::vector<bool>& xs) {
return end_sequence();
}
bool stringification_inspector::builtin_inspect(const char* x) {
return value(string_view{x, strlen(x)});
}
void stringification_inspector::sep() {
if (!result_.empty())
switch (result_.back()) {
......
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