From fecad172f32844d792158a8eff5f98bcfe40056d Mon Sep 17 00:00:00 2001 From: Scott Wheeler Date: Sun, 1 Apr 2007 22:08:44 +0000 Subject: [PATCH] Strip nulls from the end of ID3v2 text fields. Simplified version of the patch from Xavier Duret. BUG:141680 git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@649032 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- taglib/mpeg/id3v2/frames/textidentificationframe.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp index 14e96622..a74488f8 100644 --- a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp +++ b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp @@ -108,7 +108,17 @@ void TextIdentificationFrame::parseFields(const ByteVector &data) int byteAlign = d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8 ? 1 : 2; - ByteVectorList l = ByteVectorList::split(data.mid(1), textDelimiter(d->textEncoding), byteAlign); + // build a small counter to strip nulls off the end of the field + + int dataLength = data.size() - 1; + + while(dataLength > 0 && data[dataLength] == 0) + dataLength--; + + while(dataLength % byteAlign != 0) + dataLength++; + + ByteVectorList l = ByteVectorList::split(data.mid(1, dataLength), textDelimiter(d->textEncoding), byteAlign); d->fieldList.clear();