From 650a30d7940fd395bc664558ead883a6ada918a7 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Thu, 15 Apr 2021 16:13:27 +0200
Subject: [PATCH] Revert "tag/Pool: use strncmp() without strlen() to compare
 strings"

This reverts commit 1532983fb5755305a86fc37d2f35a7757d2bd66f.  This
optimization was bad because now all strings match if they are a
prefix of another string, and this caused collisions in the tag string
pool, corrupting the database.
---
 NEWS             | 2 ++
 src/tag/Pool.cxx | 5 +----
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 738904249..f72f15838 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ ver 0.22.7 (not yet released)
   - gme: support RSN files
 * storage
   - curl: don't use glibc extension
+* database
+  - simple: fix database corruption bug
 * output
   - httpd: send header "Access-Control-Allow-Origin: *"
   - wasapi: add algorithm for finding usable audio format
diff --git a/src/tag/Pool.cxx b/src/tag/Pool.cxx
index e977c6784..e5a6d57f2 100644
--- a/src/tag/Pool.cxx
+++ b/src/tag/Pool.cxx
@@ -114,10 +114,7 @@ tag_pool_get_item(TagType type, StringView value) noexcept
 	auto slot_p = tag_value_slot_p(type, value);
 	for (auto slot = *slot_p; slot != nullptr; slot = slot->next) {
 		if (slot->item.type == type &&
-		    /* 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 &&
+		    value.Equals(slot->item.value) &&
 		    slot->ref < TagPoolSlot::MAX_REF) {
 			assert(slot->ref > 0);
 			++slot->ref;