From ea9660e1cf8de10ef691e37d562da19ab518a1fb Mon Sep 17 00:00:00 2001 From: kobewi Date: Fri, 21 May 2021 15:17:43 +0200 Subject: [PATCH] Fix usage of String.left() --- core/string/ustring.cpp | 2 +- editor/editor_inspector.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 3c1afc7f2c0..49cf171f2b2 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -939,7 +939,7 @@ const char32_t *String::get_data() const { } void String::erase(int p_pos, int p_chars) { - *this = left(p_pos) + substr(p_pos + p_chars, length() - ((p_pos + p_chars))); + *this = left(MAX(p_pos, 0)) + substr(p_pos + p_chars, length() - ((p_pos + p_chars))); } String String::capitalize() const { diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 29cc4c3c467..c730277069c 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -1824,7 +1824,13 @@ void EditorInspector::update_tree() { } } - String path = basename.left(basename.rfind("/")); + String path; + { + int idx = basename.rfind("/"); + if (idx > -1) { + path = basename.left(idx); + } + } if (use_filter && filter != "") { String cat = path;