fixed an access after free in OS_X11::set_context.

Added constructor and assignment operator for CharString
from const char* to simplify memory management when working with
utf8/ascii strings for APIs taking char*.
Reworked OS_X11::set_context to use CharString and avoid some manual
memory management.
This commit is contained in:
Ibrahn Sahir
2019-03-12 12:57:22 +00:00
parent 05dda9f87c
commit 9d0b3b300c
3 changed files with 55 additions and 19 deletions

View File

@@ -123,6 +123,31 @@ const char *CharString::get_data() const {
return "";
}
CharString &CharString::operator=(const char *p_cstr) {
copy_from(p_cstr);
return *this;
}
void CharString::copy_from(const char *p_cstr) {
if (!p_cstr) {
resize(0);
return;
}
size_t len = strlen(p_cstr);
if (len == 0) {
resize(0);
return;
}
resize(len + 1); // include terminating null char
strcpy(ptrw(), p_cstr);
}
void String::copy_from(const char *p_cstr) {
if (!p_cstr) {