mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user