Ogg::XiphComment::removeField() crashes if parameter "value" is not the default String::null
Urs Fleisch
urs.fleisch at gmail.com
Sat Sep 16 12:14:59 CEST 2006
Ogg::XiphComment::removeField() crashes if parameter "value" is not the
default String::null. This happens because the iterator "it" becomes
invalidated after the call to erase().
void Ogg::XiphComment::removeField(const String &key, const String &value)
{
if(!value.isNull()) {
StringList::Iterator it = d->fieldListMap[key].begin();
for(; it != d->fieldListMap[key].end(); ++it) {
if(value == *it)
d->fieldListMap[key].erase(it);
}
}
else
d->fieldListMap.erase(key);
}
To fix it, the iterator has to be incremented before erasing, for example
like this:
void Ogg::XiphComment::removeField(const String &key, const String &value)
{
if(!value.isNull()) {
StringList::Iterator it = d->fieldListMap[key].begin();
for(; it != d->fieldListMap[key].end();) {
if(value == *it)
d->fieldListMap[key].erase(it++);
else
++it;
}
}
else
d->fieldListMap.erase(key);
}
Regards,
Urs
More information about the taglib-devel
mailing list