diff options
author | Lyuma <xn.lyuma@gmail.com> | 2023-02-03 19:19:52 -0800 |
---|---|---|
committer | Lyuma <xn.lyuma@gmail.com> | 2023-02-06 07:16:55 -0800 |
commit | 82c52eab6cf536264cb56c847ff31208691ba722 (patch) | |
tree | 6052c40cc9d578c1e18021debd8e0e0aa0d5ece9 /core | |
parent | 18e827ee46b00f6909c8c3b56bcd07d332b89cdc (diff) |
StringName: fix returning dangling data from char constructor.
Fixes a copy paste mistake in the `StringName(const char *,bool)` constructor,
to match the same form as the other two constrcutors.
This fixes a case where this constructor can return a dangling pointer and cause use-after-free.
Diffstat (limited to 'core')
-rw-r--r-- | core/string/string_name.cpp | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/core/string/string_name.cpp b/core/string/string_name.cpp index 95812fc311..df9b6b3f1a 100644 --- a/core/string/string_name.cpp +++ b/core/string/string_name.cpp @@ -226,19 +226,16 @@ StringName::StringName(const char *p_name, bool p_static) { _data = _data->next; } - if (_data) { - if (_data->refcount.ref()) { - // exists - if (p_static) { - _data->static_count.increment(); - } + if (_data && _data->refcount.ref()) { + // exists + if (p_static) { + _data->static_count.increment(); + } #ifdef DEBUG_ENABLED - if (unlikely(debug_stringname)) { - _data->debug_references++; - } -#endif + if (unlikely(debug_stringname)) { + _data->debug_references++; } - +#endif return; } @@ -288,19 +285,17 @@ StringName::StringName(const StaticCString &p_static_string, bool p_static) { _data = _data->next; } - if (_data) { - if (_data->refcount.ref()) { - // exists - if (p_static) { - _data->static_count.increment(); - } + if (_data && _data->refcount.ref()) { + // exists + if (p_static) { + _data->static_count.increment(); + } #ifdef DEBUG_ENABLED - if (unlikely(debug_stringname)) { - _data->debug_references++; - } -#endif - return; + if (unlikely(debug_stringname)) { + _data->debug_references++; } +#endif + return; } _data = memnew(_Data); @@ -348,19 +343,17 @@ StringName::StringName(const String &p_name, bool p_static) { _data = _data->next; } - if (_data) { - if (_data->refcount.ref()) { - // exists - if (p_static) { - _data->static_count.increment(); - } + if (_data && _data->refcount.ref()) { + // exists + if (p_static) { + _data->static_count.increment(); + } #ifdef DEBUG_ENABLED - if (unlikely(debug_stringname)) { - _data->debug_references++; - } -#endif - return; + if (unlikely(debug_stringname)) { + _data->debug_references++; } +#endif + return; } _data = memnew(_Data); |