diff options
author | Hein-Pieter van Braam <hp@tmm.cx> | 2019-02-22 19:27:13 +0100 |
---|---|---|
committer | Hein-Pieter van Braam <hp@tmm.cx> | 2019-02-22 19:28:19 +0100 |
commit | 4f49d09272d4885629bdde484edea875d9b45c94 (patch) | |
tree | d66d46b44bf5557c6c6f205fb3baa9e025149bef | |
parent | aef5b36bfaf6b379ddeb4809312c1fc465f35779 (diff) |
Don't crash when parse_utf8 receives a NULL pointer
This can happen when chaining calls to various string methods when the
string is empty.
-rw-r--r-- | core/ustring.cpp | 3 | ||||
-rw-r--r-- | main/tests/test_string.cpp | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index b9914fb530..ff8fcaaaaf 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -1359,6 +1359,9 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { #define _UNICERROR(m_err) print_line("Unicode error: " + String(m_err)); + if (!p_utf8) + return true; + String aux; int cstr_size = 0; diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp index 511646db0a..edc4fb0c97 100644 --- a/main/tests/test_string.cpp +++ b/main/tests/test_string.cpp @@ -1046,6 +1046,13 @@ bool test_32() { #undef STRIP_TEST } +bool test_33() { + OS::get_singleton()->print("\n\nTest 33: parse_utf8(null, -1)\n"); + + String empty; + return empty.parse_utf8(NULL, -1) == true; +} + typedef bool (*TestFunc)(void); TestFunc test_funcs[] = { @@ -1082,6 +1089,7 @@ TestFunc test_funcs[] = { test_30, test_31, test_32, + test_33, 0 }; |