mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-23 04:16:50 +01:00
Add error messages to String::bin_to_int64, and accept capital B in prefix
Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
This commit is contained in:
parent
71fe78538f
commit
756795a486
@ -1800,9 +1800,7 @@ int64_t String::hex_to_int64(bool p_with_prefix) const {
|
|||||||
|
|
||||||
int64_t String::bin_to_int64(bool p_with_prefix) const {
|
int64_t String::bin_to_int64(bool p_with_prefix) const {
|
||||||
int len = length();
|
int len = length();
|
||||||
if (len == 0 || (p_with_prefix && len < 3)) {
|
ERR_FAIL_COND_V_MSG(p_with_prefix ? len < 3 : len == 0, 0, String("Invalid binary notation length in string ") + (p_with_prefix ? "with" : "without") + " prefix \"" + *this + "\".");
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CharType *s = ptr();
|
const CharType *s = ptr();
|
||||||
|
|
||||||
@ -1813,9 +1811,7 @@ int64_t String::bin_to_int64(bool p_with_prefix) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (p_with_prefix) {
|
if (p_with_prefix) {
|
||||||
if (s[0] != '0' || s[1] != 'b') {
|
ERR_FAIL_COND_V_MSG(s[0] != '0' || LOWERCASE(s[1]) != 'b', 0, "Invalid binary notation prefix in string \"" + *this + "\".");
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
s += 2;
|
s += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1827,7 +1823,7 @@ int64_t String::bin_to_int64(bool p_with_prefix) const {
|
|||||||
if (c == '0' || c == '1') {
|
if (c == '0' || c == '1') {
|
||||||
n = c - '0';
|
n = c - '0';
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
ERR_FAIL_V_MSG(0, "Invalid binary notation character \"" + chr(*s) + "\" in string \"" + *this + "\".");
|
||||||
}
|
}
|
||||||
// Check for overflow/underflow, with special case to ensure INT64_MIN does not result in error
|
// Check for overflow/underflow, with special case to ensure INT64_MIN does not result in error
|
||||||
bool overflow = ((binary > INT64_MAX / 2) && (sign == 1 || (sign == -1 && binary != (INT64_MAX >> 1) + 1))) || (sign == -1 && binary == (INT64_MAX >> 1) + 1 && c > '0');
|
bool overflow = ((binary > INT64_MAX / 2) && (sign == 1 || (sign == -1 && binary != (INT64_MAX >> 1) + 1))) || (sign == -1 && binary == (INT64_MAX >> 1) + 1 && c > '0');
|
||||||
|
Loading…
Reference in New Issue
Block a user