-
-
Notifications
You must be signed in to change notification settings - Fork 641
Open
Description
Hello,
I suspect there is an issue with the following function, though it is certainly possible I am mistaken. It appears that the value of hash on the last line could just as easily be UINT32_MAX as it could be 0. If true the hash may overflow back to 0 and the +1 won't achieve the goal of:
// Reserv(ing) the hash result of zero as "null id"
uint32_t Clay__HashStringContentsWithConfig(Clay_String *text, Clay_TextElementConfig *config) {
uint32_t hash = 0;
if (text->isStaticallyAllocated) {
hash += (uintptr_t)text->chars;
hash += (hash << 10);
hash ^= (hash >> 6);
hash += text->length;
hash += (hash << 10);
hash ^= (hash >> 6);
} else {
hash = Clay__HashData((const uint8_t *)text->chars, text->length) % UINT32_MAX;
}
hash += config->fontId;
hash += (hash << 10);
hash ^= (hash >> 6);
hash += config->fontSize;
hash += (hash << 10);
hash ^= (hash >> 6);
hash += config->letterSpacing;
hash += (hash << 10);
hash ^= (hash >> 6);
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash + 1; // Reserve the hash result of zero as "null id"
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels