tag/Pool: use strncmp() without strlen() to compare strings

This commit is contained in:
Max Kellermann 2020-04-24 16:15:51 +02:00
parent ae5b2643da
commit 1532983fb5

View File

@ -114,7 +114,10 @@ tag_pool_get_item(TagType type, StringView value) noexcept
auto slot_p = tag_value_slot_p(type, value); auto slot_p = tag_value_slot_p(type, value);
for (auto slot = *slot_p; slot != nullptr; slot = slot->next) { for (auto slot = *slot_p; slot != nullptr; slot = slot->next) {
if (slot->item.type == type && if (slot->item.type == type &&
value.Equals(slot->item.value) && /* strncmp() only works if there are no null
bytes, which FixTagString() has already ensured
at this point */
strncmp(value.data, slot->item.value, value.size) == 0 &&
slot->ref < TagPoolSlot::MAX_REF) { slot->ref < TagPoolSlot::MAX_REF) {
assert(slot->ref > 0); assert(slot->ref > 0);
++slot->ref; ++slot->ref;