Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/cxx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,14 @@ static_assert(!std::is_same<Vec<std::uint8_t>::const_iterator,
Vec<std::uint8_t>::iterator>::value,
"Vec<T>::const_iterator != Vec<T>::iterator");

static const char *errorCopy(const char *ptr, std::size_t len) {
char *copy = new char[len];
std::memcpy(copy, ptr, len);
// Copy the error message into a private buffer and return it.
// If the allocation fails, nullptr is returned.
static const char *errorCopy(const char *ptr, std::size_t len) noexcept {
char *copy = new (std::nothrow) char[len + 1];
if (copy) {
std::memcpy(copy, ptr, len);
copy[len] = 0;
}
return copy;
}

Expand Down Expand Up @@ -496,7 +501,12 @@ Error &Error::operator=(Error &&other) &noexcept {
return *this;
}

const char *Error::what() const noexcept { return this->msg; }
const char *Error::what() const noexcept {
if (this->msg)
return this->msg;
else
return "<message not allocated>";
}

namespace {
template <typename T>
Expand Down