[Core] Fix UID encoding

Fixes edge case where `0` encoded as `uid://` instead of `uid://a`, and
fixes the size of the temporary buffer storing encoded UID strings.
This commit is contained in:
AThousandShips
2024-12-31 15:15:42 +01:00
parent 2582793d40
commit 25ecf5ec83
3 changed files with 56 additions and 3 deletions

View File

@ -47,7 +47,7 @@ String ResourceUID::get_cache_file() {
static constexpr uint8_t uuid_characters[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', '0', '1', '2', '3', '4', '5', '6', '7', '8' };
static constexpr uint32_t uuid_characters_element_count = (sizeof(uuid_characters) / sizeof(*uuid_characters));
static constexpr uint8_t max_uuid_number_length = 19; // Max 0x7FFFFFFFFFFFFFFF size is 19 digits.
static constexpr uint8_t max_uuid_number_length = 13; // Max 0x7FFFFFFFFFFFFFFF (uid://d4n4ub6itg400) size is 13 characters.
String ResourceUID::id_to_text(ID p_id) const {
if (p_id < 0) {
@ -56,12 +56,12 @@ String ResourceUID::id_to_text(ID p_id) const {
char32_t tmp[max_uuid_number_length];
uint32_t tmp_size = 0;
while (p_id) {
do {
uint32_t c = p_id % uuid_characters_element_count;
tmp[tmp_size] = uuid_characters[c];
p_id /= uuid_characters_element_count;
++tmp_size;
}
} while (p_id);
// tmp_size + uid:// (6) + 1 for null.
String txt;