diff --git a/libs/utils/include/utils/CString.h b/libs/utils/include/utils/CString.h index 8da2814f66..9ce9a0a445 100644 --- a/libs/utils/include/utils/CString.h +++ b/libs/utils/include/utils/CString.h @@ -202,9 +202,14 @@ public: CString() noexcept = default; - // cstr must be a null terminated string and length == strlen(cstr) + // Allocates memory and appends a null. This constructor can be used to hold arbitrary data + // inside the string (i.e. it can contain nulls or non-ASCII encodings). CString(const char* cstr, size_t length); + // Allocates memory and copies traditional C string content. Unlike the above constructor, this + // does not alllow embedded nulls. This is explicit because this operation is costly. + explicit CString(const char* cstr); + template explicit CString(StringLiteral const& other) noexcept // NOLINT(google-explicit-constructor) : CString(other, N - 1) { @@ -219,10 +224,6 @@ public: } - // this creates a CString from a null-terminated C string, this allocates memory and copies - // its content. this is explicit because this operation is costly. - explicit CString(const char* cstr); - CString& operator=(const CString& rhs); CString& operator=(CString&& rhs) noexcept { diff --git a/libs/utils/src/CString.cpp b/libs/utils/src/CString.cpp index 86e24164bb..5955568587 100644 --- a/libs/utils/src/CString.cpp +++ b/libs/utils/src/CString.cpp @@ -36,7 +36,6 @@ int StaticString::compare(const StaticString& rhs) const noexcept { UTILS_NOINLINE CString::CString(const char* cstr, size_t length) { if (length && cstr) { - assert(length == strlen(cstr)); Data* p = (Data*)malloc(sizeof(Data) + length + 1); p->length = (size_type)length; mCStr = (value_type*)(p + 1);