From ac99ed3cda12abe155f16a96ac0c716b2dbe6231 Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Fri, 4 Jan 2019 16:01:54 +0000 Subject: String[size()] should return a default constructed CharType As per the C++ standard 21.3.4.1 for std::string: Returns: If pos < size(), returns data()[pos]. Otherwise, if pos == size(), the const version returns charT(). Otherwise, the behavior is undefined. Since the behavior is undefined Godot now does the same thing for const and non-const versions of operator[]. This fixes #21242 and fixes #22221. --- core/ustring.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'core/ustring.cpp') diff --git a/core/ustring.cpp b/core/ustring.cpp index 23ea3f3617..0ff5cc77a4 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -58,6 +58,9 @@ #define IS_DIGIT(m_d) ((m_d) >= '0' && (m_d) <= '9') #define IS_HEX_DIGIT(m_d) (((m_d) >= '0' && (m_d) <= '9') || ((m_d) >= 'a' && (m_d) <= 'f') || ((m_d) >= 'A' && (m_d) <= 'F')) +const char CharString::_null = 0; +const CharType String::_null = 0; + bool is_symbol(CharType c) { return c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t' || c == ' '); } -- cgit v1.2.3