diff options
| author | yeojunh <yeojunhann@gmail.com> | 2024-10-19 22:13:14 -0700 |
|---|---|---|
| committer | yeojunh <yeojunhann@gmail.com> | 2024-10-20 00:22:08 -0700 |
| commit | b3b24ded19d5aeb015ab6633b2234f8c27b7c53e (patch) | |
| tree | 61826681b1f5df83a6ce5e81f41ef6421992834f /core/string | |
| parent | 44fa552343722bb048e2d7c6d3661174a95a8a3c (diff) | |
| download | redot-engine-b3b24ded19d5aeb015ab6633b2234f8c27b7c53e.tar.gz | |
Add checks for valid base in String::num_int64, uint64().
- Ensure String::num_int64, uint64 returns an empty string for bases less than 2 or greater than 36.
- Added corresponding test cases to verify the behavior.
- Error messages are printed when invalid bases are encountered. These messages are suppressed in the test output.
Diffstat (limited to 'core/string')
| -rw-r--r-- | core/string/ustring.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index e6f7492a18..4e9eb922f6 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1850,6 +1850,8 @@ String String::num(double p_num, int p_decimals) { } String String::num_int64(int64_t p_num, int base, bool capitalize_hex) { + ERR_FAIL_COND_V_MSG(base < 2 || base > 36, "", "Cannot convert to base " + itos(base) + ", since the value is " + (base < 2 ? "less than 2." : "greater than 36.")); + bool sign = p_num < 0; int64_t n = p_num; @@ -1888,6 +1890,8 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) { } String String::num_uint64(uint64_t p_num, int base, bool capitalize_hex) { + ERR_FAIL_COND_V_MSG(base < 2 || base > 36, "", "Cannot convert to base " + itos(base) + ", since the value is " + (base < 2 ? "less than 2." : "greater than 36.")); + uint64_t n = p_num; int chars = 0; |
