From c000e9c1f409c926b766333c615c321eab82e366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Schre=CC=81ter?= Date: Fri, 24 Feb 2023 21:51:46 +0100 Subject: [PATCH] Add NUL character at the end of copied error message C++ error message returned by `what` must be NUL-terminated. However, the current copy function only copied the characters, but didn't add the NUL. Allocate one more byte and set it to NUL. --- src/cxx.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cxx.cc b/src/cxx.cc index 4958eb08b..d449429da 100644 --- a/src/cxx.cc +++ b/src/cxx.cc @@ -449,8 +449,9 @@ static_assert(!std::is_same::const_iterator, "Vec::const_iterator != Vec::iterator"); static const char *errorCopy(const char *ptr, std::size_t len) { - char *copy = new char[len]; + char *copy = new char[len + 1]; std::memcpy(copy, ptr, len); + copy[len] = 0; return copy; }