Skip to content

Commit 2805a91

Browse files
committed
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.
1 parent 7528dde commit 2805a91

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/cxx.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,9 @@ static_assert(!std::is_same<Vec<std::uint8_t>::const_iterator,
449449
"Vec<T>::const_iterator != Vec<T>::iterator");
450450

451451
static const char *errorCopy(const char *ptr, std::size_t len) {
452-
char *copy = new char[len];
452+
char *copy = new char[len + 1];
453453
std::memcpy(copy, ptr, len);
454+
copy[len] = 0;
454455
return copy;
455456
}
456457

0 commit comments

Comments
 (0)