Commit 7dd723d8 authored by Urs Fleisch's avatar Urs Fleisch
Browse files

Removed unneccessary checks of heap constructed objects.

parent 8ec8835c
......@@ -6,7 +6,7 @@
* \author Urs Fleisch
* \date 04 Oct 2005
*
* Copyright (C) 2005-2011 Urs Fleisch
* Copyright (C) 2005-2012 Urs Fleisch
*
* This file is part of Kid3.
*
......@@ -142,68 +142,65 @@ void FlacFile::readTags(bool force)
}
if (m_chain && m_chain->is_valid()) {
if (m_chain->read(fnIn)) {
FLAC::Metadata::Iterator* mdit = new FLAC::Metadata::Iterator;
if (mdit) {
mdit->init(*m_chain);
while (mdit->is_valid()) {
::FLAC__MetadataType mdt = mdit->get_block_type();
if (mdt == FLAC__METADATA_TYPE_STREAMINFO) {
FLAC::Metadata::Prototype* proto = mdit->get_block();
if (proto) {
FLAC::Metadata::StreamInfo* si =
dynamic_cast<FLAC::Metadata::StreamInfo*>(proto);
m_fileInfo.read(si);
delete proto;
}
} else if (mdt == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
FLAC::Metadata::Prototype* proto = mdit->get_block();
if (proto) {
FLAC::Metadata::VorbisComment* vc =
dynamic_cast<FLAC::Metadata::VorbisComment*>(proto);
if (vc && vc->is_valid()) {
unsigned numComments = vc->get_num_comments();
for (unsigned i = 0; i < numComments; ++i) {
FLAC::Metadata::VorbisComment::Entry entry =
vc->get_comment(i);
if (entry.is_valid()) {
QString name =
QString::fromUtf8(entry.get_field_name(),
entry.get_field_name_length()).
trimmed().toUpper();
QString value =
QString::fromUtf8(entry.get_field_value(),
entry.get_field_value_length()).
trimmed();
if (!value.isEmpty()) {
m_comments.push_back(
CommentField(name, value));
}
FLAC::Metadata::Iterator mdit;
mdit.init(*m_chain);
while (mdit.is_valid()) {
::FLAC__MetadataType mdt = mdit.get_block_type();
if (mdt == FLAC__METADATA_TYPE_STREAMINFO) {
FLAC::Metadata::Prototype* proto = mdit.get_block();
if (proto) {
FLAC::Metadata::StreamInfo* si =
dynamic_cast<FLAC::Metadata::StreamInfo*>(proto);
m_fileInfo.read(si);
delete proto;
}
} else if (mdt == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
FLAC::Metadata::Prototype* proto = mdit.get_block();
if (proto) {
FLAC::Metadata::VorbisComment* vc =
dynamic_cast<FLAC::Metadata::VorbisComment*>(proto);
if (vc && vc->is_valid()) {
unsigned numComments = vc->get_num_comments();
for (unsigned i = 0; i < numComments; ++i) {
FLAC::Metadata::VorbisComment::Entry entry =
vc->get_comment(i);
if (entry.is_valid()) {
QString name =
QString::fromUtf8(entry.get_field_name(),
entry.get_field_name_length()).
trimmed().toUpper();
QString value =
QString::fromUtf8(entry.get_field_value(),
entry.get_field_value_length()).
trimmed();
if (!value.isEmpty()) {
m_comments.push_back(
CommentField(name, value));
}
}
}
delete proto;
}
delete proto;
}
}
#ifdef HAVE_FLAC_PICTURE
else if (mdt == FLAC__METADATA_TYPE_PICTURE) {
FLAC::Metadata::Prototype* proto = mdit->get_block();
if (proto) {
FLAC::Metadata::Picture* pic =
dynamic_cast<FLAC::Metadata::Picture*>(proto);
if (pic) {
Frame frame(Frame::FT_Picture, "", "", pictureNr++);
getPicture(frame, pic);
m_pictures.push_back(frame);
}
delete proto;
else if (mdt == FLAC__METADATA_TYPE_PICTURE) {
FLAC::Metadata::Prototype* proto = mdit.get_block();
if (proto) {
FLAC::Metadata::Picture* pic =
dynamic_cast<FLAC::Metadata::Picture*>(proto);
if (pic) {
Frame frame(Frame::FT_Picture, "", "", pictureNr++);
getPicture(frame, pic);
m_pictures.push_back(frame);
}
delete proto;
}
}
#endif
if (!mdit->next()) {
break;
}
if (!mdit.next()) {
break;
}
delete mdit;
}
}
}
......@@ -240,97 +237,85 @@ bool FlacFile::writeTags(bool force, bool* renamed, bool preserve)
PictureList::iterator pictureIt = m_pictures.begin();
#endif
m_chain->sort_padding();
FLAC::Metadata::Iterator* mdit = new FLAC::Metadata::Iterator;
if (mdit) {
mdit->init(*m_chain);
while (mdit->is_valid()) {
::FLAC__MetadataType mdt = mdit->get_block_type();
if (mdt == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
if (commentsSet) {
mdit->delete_block(true);
} else {
FLAC::Metadata::Prototype* proto = mdit->get_block();
if (proto) {
FLAC::Metadata::VorbisComment* vc =
dynamic_cast<FLAC::Metadata::VorbisComment*>(proto);
if (vc && vc->is_valid()) {
setVorbisComment(vc);
commentsSet = true;
}
delete proto;
FLAC::Metadata::Iterator mdit;
mdit.init(*m_chain);
while (mdit.is_valid()) {
::FLAC__MetadataType mdt = mdit.get_block_type();
if (mdt == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
if (commentsSet) {
mdit.delete_block(true);
} else {
FLAC::Metadata::Prototype* proto = mdit.get_block();
if (proto) {
FLAC::Metadata::VorbisComment* vc =
dynamic_cast<FLAC::Metadata::VorbisComment*>(proto);
if (vc && vc->is_valid()) {
setVorbisComment(vc);
commentsSet = true;
}
delete proto;
}
}
}
#ifdef HAVE_FLAC_PICTURE
else if (mdt == FLAC__METADATA_TYPE_PICTURE) {
if (pictureIt != m_pictures.end()) {
FLAC::Metadata::Prototype* proto = mdit->get_block();
if (proto) {
FLAC::Metadata::Picture* pic =
dynamic_cast<FLAC::Metadata::Picture*>(proto);
if (pic) {
setPicture(*pictureIt++, pic);
pictureSet = true;
}
delete proto;
}
} else {
mdit->delete_block(false);
pictureRemoved = true;
}
} else if (mdt == FLAC__METADATA_TYPE_PADDING) {
if (pictureIt != m_pictures.end()) {
else if (mdt == FLAC__METADATA_TYPE_PICTURE) {
if (pictureIt != m_pictures.end()) {
FLAC::Metadata::Prototype* proto = mdit.get_block();
if (proto) {
FLAC::Metadata::Picture* pic =
new FLAC::Metadata::Picture;
dynamic_cast<FLAC::Metadata::Picture*>(proto);
if (pic) {
setPicture(*pictureIt, pic);
if (mdit->set_block(pic)) {
++pictureIt;
pictureSet = true;
} else {
delete pic;
}
setPicture(*pictureIt++, pic);
pictureSet = true;
}
} else if (pictureRemoved) {
mdit->delete_block(false);
delete proto;
}
} else {
mdit.delete_block(false);
pictureRemoved = true;
}
} else if (mdt == FLAC__METADATA_TYPE_PADDING) {
if (pictureIt != m_pictures.end()) {
FLAC::Metadata::Picture* pic = new FLAC::Metadata::Picture;
setPicture(*pictureIt, pic);
if (mdit.set_block(pic)) {
++pictureIt;
pictureSet = true;
} else {
delete pic;
}
} else if (pictureRemoved) {
mdit.delete_block(false);
}
}
#endif
if (!mdit->next()) {
if (!commentsSet) {
FLAC::Metadata::VorbisComment* vc =
new FLAC::Metadata::VorbisComment;
if (vc) {
if (vc->is_valid()) {
setVorbisComment(vc);
if (mdit->insert_block_after(vc)) {
commentsSet = true;
}
}
if (!commentsSet) {
delete vc;
}
if (!mdit.next()) {
if (!commentsSet) {
FLAC::Metadata::VorbisComment* vc = new FLAC::Metadata::VorbisComment;
if (vc->is_valid()) {
setVorbisComment(vc);
if (mdit.insert_block_after(vc)) {
commentsSet = true;
}
}
if (!commentsSet) {
delete vc;
}
}
#ifdef HAVE_FLAC_PICTURE
while (pictureIt != m_pictures.end()) {
FLAC::Metadata::Picture* pic =
new FLAC::Metadata::Picture;
if (pic) {
setPicture(*pictureIt, pic);
if (mdit->insert_block_after(pic)) {
pictureSet = true;
} else {
delete pic;
}
}
++pictureIt;
while (pictureIt != m_pictures.end()) {
FLAC::Metadata::Picture* pic = new FLAC::Metadata::Picture;
setPicture(*pictureIt, pic);
if (mdit.insert_block_after(pic)) {
pictureSet = true;
} else {
delete pic;
}
#endif
break;
++pictureIt;
}
#endif
break;
}
delete mdit;
}
#ifdef HAVE_FLAC_PICTURE
if ((commentsSet || pictureSet) &&
......
......@@ -6,7 +6,7 @@
* \author Urs Fleisch
* \date 9 Jan 2003
*
* Copyright (C) 2003-2011 Urs Fleisch
* Copyright (C) 2003-2012 Urs Fleisch
*
* This file is part of Kid3.
*
......@@ -106,10 +106,8 @@ void Mp3File::readTags(bool force)
}
if (!m_tagV1) {
m_tagV1 = new ID3_Tag;
if (m_tagV1) {
m_tagV1->Link(fn, ID3TT_ID3V1);
markTag1Unchanged();
}
m_tagV1->Link(fn, ID3TT_ID3V1);
markTag1Unchanged();
}
if (force && m_tagV2) {
......@@ -119,10 +117,8 @@ void Mp3File::readTags(bool force)
}
if (!m_tagV2) {
m_tagV2 = new ID3_Tag;
if (m_tagV2) {
m_tagV2->Link(fn, ID3TT_ID3V2);
markTag2Unchanged();
}
m_tagV2->Link(fn, ID3TT_ID3V2);
markTag2Unchanged();
}
if (force) {
......@@ -245,28 +241,25 @@ static QString fixUpUnicode(const unicode_t* str, size_t numChars)
QString text;
if (numChars > 0 && str && *str) {
QChar* qcarray = new QChar[numChars];
if (qcarray) {
// Unfortunately, Unicode support in id3lib is rather buggy
// in the current version: The codes are mirrored.
// In the hope that my patches will be included, I try here
// to work around these bugs.
size_t i;
size_t numZeroes = 0;
for (i = 0; i < numChars; i++) {
qcarray[i] =
UNICODE_SUPPORT_BUGGY ?
(ushort)(((str[i] & 0x00ff) << 8) |
((str[i] & 0xff00) >> 8)) :
(ushort)str[i];
if (qcarray[i].isNull()) { ++numZeroes; }
}
// remove a single trailing zero character
if (numZeroes == 1 && qcarray[numChars - 1].isNull()) {
--numChars;
}
text = QString(qcarray, numChars);
delete [] qcarray;
// Unfortunately, Unicode support in id3lib is rather buggy
// in the current version: The codes are mirrored.
// In the hope that my patches will be included, I try here
// to work around these bugs.
size_t numZeroes = 0;
for (size_t i = 0; i < numChars; i++) {
qcarray[i] =
UNICODE_SUPPORT_BUGGY ?
(ushort)(((str[i] & 0x00ff) << 8) |
((str[i] & 0xff00) >> 8)) :
(ushort)str[i];
if (qcarray[i].isNull()) { ++numZeroes; }
}
// remove a single trailing zero character
if (numZeroes == 1 && qcarray[numChars - 1].isNull()) {
--numChars;
}
text = QString(qcarray, numChars);
delete [] qcarray;
}
return text;
}
......@@ -436,17 +429,14 @@ static unicode_t* newFixedUpUnicode(const QString& text)
const QChar* qcarray = text.unicode();
uint unicode_size = text.length();
unicode_t* unicode = new unicode_t[unicode_size + 1];
if (unicode) {
uint i;
for (i = 0; i < unicode_size; i++) {
unicode[i] = (ushort)qcarray[i].unicode();
if (UNICODE_SUPPORT_BUGGY) {
unicode[i] = (ushort)(((unicode[i] & 0x00ff) << 8) |
((unicode[i] & 0xff00) >> 8));
}
for (uint i = 0; i < unicode_size; i++) {
unicode[i] = (ushort)qcarray[i].unicode();
if (UNICODE_SUPPORT_BUGGY) {
unicode[i] = (ushort)(((unicode[i] & 0x00ff) << 8) |
((unicode[i] & 0xff00) >> 8));
}
unicode[unicode_size] = 0;
}
unicode[unicode_size] = 0;
return unicode;
}
......@@ -1711,48 +1701,46 @@ bool Mp3File::addFrameV2(Frame& frame)
}
if (id != ID3FID_NOFRAME && id != ID3FID_SETSUBTITLE && m_tagV2) {
ID3_Frame* id3Frame = new ID3_Frame(id);
if (id3Frame) {
ID3_Field* fld = id3Frame->GetField(ID3FN_TEXT);
if (fld) {
ID3_TextEnc enc = getDefaultTextEncoding();
ID3_Field* encfld = id3Frame->GetField(ID3FN_TEXTENC);
if (encfld) {
encfld->Set(enc);
}
fld->SetEncoding(enc);
ID3_Field* fld = id3Frame->GetField(ID3FN_TEXT);
if (fld) {
ID3_TextEnc enc = getDefaultTextEncoding();
ID3_Field* encfld = id3Frame->GetField(ID3FN_TEXTENC);
if (encfld) {
encfld->Set(enc);
}
if (id == ID3FID_USERTEXT && !frame.getName().startsWith("TXXX")) {
fld = id3Frame->GetField(ID3FN_DESCRIPTION);
if (fld) {
setString(fld, frame.getName());
}
} else if (id == ID3FID_PICTURE) {
fld = id3Frame->GetField(ID3FN_MIMETYPE);
if (fld) {
setString(fld, "image/jpeg");
}
fld = id3Frame->GetField(ID3FN_PICTURETYPE);
if (fld) {
fld->Set(ID3PT_COVERFRONT);
}
fld->SetEncoding(enc);
}
if (id == ID3FID_USERTEXT && !frame.getName().startsWith("TXXX")) {
fld = id3Frame->GetField(ID3FN_DESCRIPTION);
if (fld) {
setString(fld, frame.getName());
}
if (!frame.fieldList().empty()) {
setId3v2Frame(id3Frame, frame);
} else if (id == ID3FID_PICTURE) {
fld = id3Frame->GetField(ID3FN_MIMETYPE);
if (fld) {
setString(fld, "image/jpeg");
}
Frame::Type type;
const char* name;
getTypeStringForId3libFrameId(id, type, name);
m_tagV2->AttachFrame(id3Frame);
frame.setInternalName(name);
frame.setIndex(m_tagV2->NumFrames() - 1);
if (frame.fieldList().empty()) {
// add field list to frame
getFieldsFromId3Frame(id3Frame, frame.fieldList());
frame.setFieldListFromValue();
fld = id3Frame->GetField(ID3FN_PICTURETYPE);
if (fld) {
fld->Set(ID3PT_COVERFRONT);
}
markTag2Changed(frame.getType());
return true;
}
if (!frame.fieldList().empty()) {
setId3v2Frame(id3Frame, frame);
}
Frame::Type type;
const char* name;
getTypeStringForId3libFrameId(id, type, name);
m_tagV2->AttachFrame(id3Frame);
frame.setInternalName(name);
frame.setIndex(m_tagV2->NumFrames() - 1);
if (frame.fieldList().empty()) {
// add field list to frame
getFieldsFromId3Frame(id3Frame, frame.fieldList());
frame.setFieldListFromValue();
}
markTag2Changed(frame.getType());
return true;
}
// Try the superclass method
......
......@@ -6,7 +6,7 @@
* \author Urs Fleisch
* \date 12 Sep 2006
*
* Copyright (C) 2006-2007 Urs Fleisch
* Copyright (C) 2006-2012 Urs Fleisch
*
* This file is part of Kid3.
*
......@@ -1137,9 +1137,6 @@ bool setId3v2Unicode(TagLib::Tag* tag, const QString& qstr, const TagLib::String
} else {
frame = new TagLib::ID3v2::CommentsFrame(enc);
}
if (!frame) {
return false;
}
frame->setText(tstr);
#ifdef WIN32
// freed in Windows DLL => must be allocated in the same DLL
......@@ -1278,28 +1275,25 @@ void TagLibFile::setTrackV2(const QString& track)
if (num != static_cast<int>(m_tagV2->track())) {
TagLib::ID3v2::Tag* id3v2Tag = dynamic_cast<TagLib::ID3v2::Tag*>(m_tagV2);
if (id3v2Tag) {
TagLib::ID3v2::TextIdentificationFrame* frame;
TagLib::String tstr = str.isEmpty() ?
TagLib::String::null : QSTRING_TO_TSTRING(str);
if (!setId3v2Unicode(m_tagV2, str, tstr, "TRCK")) {
if ((frame = new TagLib::ID3v2::TextIdentificationFrame(
"TRCK", getDefaultTextEncoding())) != 0) {
frame->setText(tstr);
id3v2Tag->removeFrames("TRCK");
TagLib::ID3v2::TextIdentificationFrame* frame =
new TagLib::ID3v2::TextIdentificationFrame(
"TRCK", getDefaultTextEncoding());
frame->setText(tstr);
id3v2Tag->removeFrames("TRCK");
#ifdef WIN32
// freed in Windows DLL => must be allocated in the same DLL
TagLib::ID3v2::Frame* dllAllocatedFrame =
TagLib::ID3v2::FrameFactory::instance()->createFrame(frame->render());
if (dllAllocatedFrame) {
id3v2Tag->addFrame(dllAllocatedFrame);
}
delete frame;
// freed in Windows DLL => must be allocated in the same DLL
TagLib::ID3v2::Frame* dllAllocatedFrame =
TagLib::ID3v2::FrameFactory::instance()->createFrame(frame->render());
if (dllAllocatedFrame) {
id3v2Tag->addFrame(dllAllocatedFrame);
}
delete frame;
#else
id3v2Tag->addFrame(frame);
id3v2Tag->addFrame(frame);
#endif
} else {
m_tagV2->setTrack(num);
}
}
} else {
m_tagV2->setTrack(num);
......@@ -3760,22 +3754,18 @@ bool TagLibFile::addFrameV2(Frame& frame)
id3Frame = new TagLib::ID3v2::CommentsFrame(enc);
} else if (frameId == "APIC") {
id3Frame = new TagLib::ID3v2::AttachedPictureFrame;
if (id3Frame) {
((TagLib::ID3v2::AttachedPictureFrame*)id3Frame)->setTextEncoding(enc);
((TagLib::ID3v2::AttachedPictureFrame*)id3Frame)->setMimeType(
"image/jpeg");
((TagLib::ID3v2::AttachedPictureFrame*)id3Frame)->setType(
TagLib::ID3v2::AttachedPictureFrame::FrontCover);
}
((TagLib::ID3v2::AttachedPictureFrame*)id3Frame)->setTextEncoding(enc);
((TagLib::ID3v2::AttachedPictureFrame*)id3Frame)->setMimeType(
"image/jpeg");
((TagLib::ID3v2::AttachedPictureFrame*)id3Frame)->setType(
TagLib::ID3v2::AttachedPictureFrame::FrontCover);
} else if (frameId == "UFID") {
// the bytevector must not be empty
id3Frame = new TagLib::ID3v2::UniqueFileIdentifierFrame(
TagLib::String(), TagLib::ByteVector(" "));
} else if (frameId == "GEOB") {
id3Frame = new TagLib::ID3v2::GeneralEncapsulatedObjectFrame;
if (id3Frame) {
((TagLib::ID3v2::GeneralEncapsulatedObjectFrame*)id3Frame)->setTextEncoding(enc);
}
((TagLib::ID3v2::GeneralEncapsulatedObjectFrame*)id3Frame)->setTextEncoding(enc);
} else if (frameId.startsWith("W")) {
if (frameId == "WXXX") {
id3Frame = new TagLib::ID3v2::UserUrlLinkFrame(enc);
......@@ -3786,9 +3776,7 @@ bool TagLibFile::addFrameV2(Frame& frame)
}
} else if (frameId == "USLT") {
id3Frame = new TagLib::ID3v2::UnsynchronizedLyricsFrame(enc);
if (id3Frame) {
((TagLib::ID3v2::UnsynchronizedLyricsFrame*)id3Frame)->setLanguage("eng");
}
((TagLib::ID3v2::UnsynchronizedLyricsFrame*)id3Frame)->setLanguage("eng");
}
if (!id3Frame) {
TagLib::ID3v2::UserTextIdentificationFrame* txxxFrame =
......
......@@ -6,7 +6,7 @@
* \author Urs Fleisch
* \date 22 Feb 2007
*
* Copyright (C) 2007 Urs Fleisch
* Copyright (C) 2007-2012 Urs Fleisch
*
* This file is part of Kid3.
*
......@@ -46,25 +46,21 @@ ExternalProcess::OutputViewer::OutputViewer(QWidget* parent) : QDialog(parent)
setModal(false);
QVBoxLayout* vlayout = new QVBoxLayout(this);
m_textEdit = new QTextEdit(this);
if (vlayout && m_textEdit) {
vlayout->setSpacing(6);
vlayout->setMargin(6);
m_textEdit->setReadOnly(true);
vlayout->addWidget(m_textEdit);
QHBoxLayout* buttonLayout = new QHBoxLayout;
QPushButton* clearButton = new QPushButton(i18n("C&lear"), this);
QSpacerItem* hspacer = new QSpacerItem(16, 0, QSizePolicy::Expanding,
QSizePolicy::Minimum);
QPushButton* closeButton = new QPushButton(i18n("&Close"), this);
if (buttonLayout && clearButton && hspacer && closeButton) {