diff options
author | Hein-Pieter van Braam <hp@tmm.cx> | 2019-04-23 06:14:49 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-23 06:14:49 +0300 |
commit | 01f7166d09662889ae8e3a827ef95c2004ec3e53 (patch) | |
tree | 9ac6fb20dcf0edf0c3e14a10fb202b7d1020f307 /core | |
parent | a76d59cba9146f91f386fbfe097e62300e5d0862 (diff) | |
parent | 9d0b3b300cd219ebec9287b3f97c3c0e220cd18d (diff) |
Merge pull request #26961 from ibrahn/fix-x11setcontext-access-freed
fixed an access after free in OS_X11::set_context. (long version)
Diffstat (limited to 'core')
-rw-r--r-- | core/ustring.cpp | 25 | ||||
-rw-r--r-- | core/ustring.h | 5 |
2 files changed, 30 insertions, 0 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index d60bd16921..78feddb229 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -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) { diff --git a/core/ustring.h b/core/ustring.h index 85103057df..e2e62874d6 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -101,12 +101,17 @@ public: _cowdata._ref(p_str._cowdata); return *this; } + _FORCE_INLINE_ CharString(const char *p_cstr) { copy_from(p_cstr); } + CharString &operator=(const char *p_cstr); bool operator<(const CharString &p_right) const; CharString &operator+=(char p_char); int length() const { return size() ? size() - 1 : 0; } const char *get_data() const; operator const char *() const { return get_data(); }; + +protected: + void copy_from(const char *p_cstr); }; typedef wchar_t CharType; |