CString can construct from a string_view (#3677)

* CString can construct from a string_view

(string_views lack a null terminator)

* Update libs/utils/src/CString.cpp

Co-authored-by: Mathias Agopian <pixelflinger@gmail.com>
This commit is contained in:
Adrian Perez
2021-03-23 00:46:18 -07:00
committed by GitHub
parent 3ec3f222c5
commit a33c85bdd4

View File

@@ -40,7 +40,8 @@ CString::CString(const char* cstr, size_t length) {
p->length = (size_type)length;
mCStr = (value_type*)(p + 1);
// we don't use memcpy here to avoid a call to libc, the generated code is pretty good.
std::uninitialized_copy_n(cstr, length + 1, mCStr);
std::uninitialized_copy_n(cstr, length, mCStr);
mCStr[length] = '\0';
}
}