From 24575aab233a9202c24a892a6d6cd40d287f71b3 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Wed, 3 Feb 2016 20:21:04 +0900 Subject: [PATCH] Remove strnlen() since some compilers lack it. --- taglib/ape/apetag.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index 9c8d8217..d49d0700 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -42,7 +42,6 @@ #include "apefooter.h" #include "apeitem.h" - using namespace TagLib; using namespace APE; @@ -411,11 +410,16 @@ void APE::Tag::parse(const ByteVector &data) for(unsigned int i = 0; i < d->footer.itemCount() && pos <= data.size() - 11; i++) { - const char *key = &data[pos + 8]; - const size_t keyLength = ::strnlen(key, data.size() - pos - 8); - const size_t valLegnth = data.toUInt(pos, false); + const int nullPos = data.find('\0', pos + 8); + if(nullPos < 0) { + debug("APE::Tag::parse() - Couldn't find a key/value separator. Stopped parsing."); + return; + } - if(isKeyValid(key, keyLength)){ + const unsigned int keyLength = nullPos - pos - 8; + const unsigned int valLegnth = data.toUInt(pos, false); + + if(isKeyValid(&data[pos + 8], keyLength)){ APE::Item item; item.parse(data.mid(pos)); @@ -425,6 +429,6 @@ void APE::Tag::parse(const ByteVector &data) debug("APE::Tag::parse() - Skipped an item due to an invalid key."); } - pos += static_cast(keyLength + valLegnth + 9); + pos += keyLength + valLegnth + 9; } }