[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [k3b/cdrskin] /: Fix issues detected by clang-analyzer
From:       Leslie Zhai <xiangzhai83 () gmail ! com>
Date:       2016-11-14 8:07:09
Message-ID: E1c6CIH-0002K3-Di () code ! kde ! org
[Download RAW message or body]

Git commit cf01ff3159dbddb97e0e67246dee16441a64984a by Leslie Zhai.
Committed on 14/11/2016 at 08:06.
Pushed by lesliezhai into branch 'cdrskin'.

Fix issues detected by clang-analyzer

M  +2    -2    INSTALL.txt
M  +2    -0    libk3b/projects/audiocd/k3baudiodoc.cpp
M  +4    -0    libk3b/projects/movixcd/k3bmovixdocpreparer.cpp
M  +3    -1    libk3b/projects/movixcd/k3bmovixprogram.cpp
M  +4    -2    libk3b/projects/videocd/mpeginfo/k3bmpeginfo.cpp
M  +3    -5    libk3bdevice/k3bdevice_mmc.cpp
M  +3    -1    plugins/project/audiometainforenamer/k3baudiometainforenamerplugin.cpp
M  +1    -0    src/k3b.cpp
M  +3    -0    src/k3bmetaitemmodel.cpp
M  +11   -9    src/misc/k3bmediacopydialog.cpp
M  +1    -1    src/projects/k3baudioprojectmodel.cpp
M  +7    -6    src/projects/k3bdataurladdingdialog.cpp
M  +4    -2    src/rip/videodvd/k3bvideodvdrippingpreview.cpp

http://commits.kde.org/k3b/cf01ff3159dbddb97e0e67246dee16441a64984a

diff --git a/INSTALL.txt b/INSTALL.txt
index cd2f589..880b02b 100644
--- a/INSTALL.txt
+++ b/INSTALL.txt
@@ -36,7 +36,7 @@ After that it's all the same:
 
 For debug:
 
-  cmake .. -DCMAKE_INSTALL_PREFIX=/usr    \
+  scan-build -k -v -V cmake .. -DCMAKE_INSTALL_PREFIX=/usr    \
     -DKDE_INSTALL_LIBDIR=lib    \
     -DKDE_INSTALL_LIBEXECDIR=lib    \
     -DKDE_INSTALL_USE_QT_SYS_PATHS=ON   \
@@ -47,7 +47,7 @@ For debug:
 If the cmake run was successful you are presented with a list of configure results \
that shows  which optional features are enabled. Now just compile K3b:
 
-  make
+  scan-build -k -v -V make
 
 Now you are ready to install:
 
diff --git a/libk3b/projects/audiocd/k3baudiodoc.cpp \
b/libk3b/projects/audiocd/k3baudiodoc.cpp index c9227cd..362eb82 100644
--- a/libk3b/projects/audiocd/k3baudiodoc.cpp
+++ b/libk3b/projects/audiocd/k3baudiodoc.cpp
@@ -721,11 +721,13 @@ bool K3b::AudioDoc::loadDocumentData( QDomElement* root )
                                 }
                                 else {
                                     qDebug() << "(K3b::AudioDoc) invalid cdtrack \
source."; +                                    delete track;
                                     return false;
                                 }
                             }
                             else {
                                 qDebug() << "(K3b::AudioDoc) unknown source type: " \
<< sourceElem.nodeName(); +                                delete track;
                                 return false;
                             }
                         }
diff --git a/libk3b/projects/movixcd/k3bmovixdocpreparer.cpp \
b/libk3b/projects/movixcd/k3bmovixdocpreparer.cpp index c60a9d5..9c49ccd 100644
--- a/libk3b/projects/movixcd/k3bmovixdocpreparer.cpp
+++ b/libk3b/projects/movixcd/k3bmovixdocpreparer.cpp
@@ -257,6 +257,8 @@ bool K3b::MovixDocPreparer::addMovixFiles()
     // first of all we create the directories
     d->isolinuxDir = new K3b::DirItem( "isolinux" );
     d->movixDir = new K3b::DirItem( "movix" );
+    if (d->doc == Q_NULLPTR)
+        return false;
     d->doc->root()->addDataItem( d->isolinuxDir );
     d->doc->root()->addDataItem( d->movixDir );
     K3b::DirItem* kernelDir = d->doc->addEmptyDir( "kernel", d->isolinuxDir );
@@ -362,6 +364,8 @@ bool K3b::MovixDocPreparer::addMovixFilesNew()
     // 3. add movixrc and movix.list files
     // 4. set weights for isolinux files
 
+    if (d->doc == Q_NULLPTR)
+        return false;
     // FIXME: use the settings from the doc
     const QStringList files = d->eMovixBin->files( d->doc->keyboardLayout(),
                                              d->doc->subtitleFontset(),
diff --git a/libk3b/projects/movixcd/k3bmovixprogram.cpp \
b/libk3b/projects/movixcd/k3bmovixprogram.cpp index 6afb44e..0d767d3 100644
--- a/libk3b/projects/movixcd/k3bmovixprogram.cpp
+++ b/libk3b/projects/movixcd/k3bmovixprogram.cpp
@@ -70,7 +70,7 @@ bool K3b::MovixProgram::scan( const QString& p )
         return false;
     }
 
-    if( bin->version() >= K3b::Version( 0, 9, 0 ) )
+    if( bin && bin->version() >= K3b::Version( 0, 9, 0 ) )
         return scanNewEMovix( bin, path );
     else
         return scanOldEMovix( bin, path );
@@ -106,6 +106,8 @@ bool K3b::MovixProgram::scanOldEMovix( K3b::MovixBin* bin, const \
QString& path )  //
     // first check if all necessary directories are present
     //
+    if (bin == Q_NULLPTR)
+        return false;
     QDir dir( bin->movixDataDir() );
     QStringList subdirs = dir.entryList( QDir::Dirs );
     if( !subdirs.contains( "boot-messages" ) ) {
diff --git a/libk3b/projects/videocd/mpeginfo/k3bmpeginfo.cpp \
b/libk3b/projects/videocd/mpeginfo/k3bmpeginfo.cpp index ea24c95..a1ae0db 100644
--- a/libk3b/projects/videocd/mpeginfo/k3bmpeginfo.cpp
+++ b/libk3b/projects/videocd/mpeginfo/k3bmpeginfo.cpp
@@ -257,7 +257,9 @@ llong K3b::MpegInfo::MpegParsePacket ( llong offset )
         offset += 4;
         size = GetSize( offset );
         offset += 2;
-        // qDebug() << QString( "offset = %1, size = %2" ).arg( offset ).arg( size \
); +#ifdef K3B_DEBUG
+        qDebug() << QString( "offset = %1, size = %2" ).arg( offset ).arg( size );
+#endif
 
         switch ( mark ) {
         case MPEG_SYSTEM_HEADER_CODE:
@@ -760,7 +762,7 @@ void K3b::MpegInfo::ParseVideo ( llong offset, byte marker )
 
     mpeg_info->video[ v_idx ].bitrate = 400 * brate;
 
-    byte mark;
+    byte mark = -1;
     while ( true ) {
         offset = FindNextMarker( offset, &mark );
         if ( mark == MPEG_GOP_CODE )
diff --git a/libk3bdevice/k3bdevice_mmc.cpp b/libk3bdevice/k3bdevice_mmc.cpp
index 4493edb..bbd3331 100644
--- a/libk3bdevice/k3bdevice_mmc.cpp
+++ b/libk3bdevice/k3bdevice_mmc.cpp
@@ -202,9 +202,7 @@ bool K3b::Device::Device::getPerformance( UByteArray& data,
     //        return types. "Defect Status Data" for example might return way more \
                data.
     // FIXME: Since we only use getPerformance for writing speeds and without a \
proper length  //        those do not make sense it is better to fail here anyway.
-    if( (dataLen-8) % descLen ||
-        dataLen <= 8 ||
-        dataLen > 2048 ) {
+    if( descLen == 0 || (dataLen-8) % descLen || dataLen <= 8 || dataLen > 2048 ) {
         qDebug() << "(K3b::Device::Device) " << blockDeviceName()
                  << ": GET PERFORMANCE reports bogus dataLen: " << dataLen << endl;
         return false;
@@ -586,7 +584,7 @@ bool K3b::Device::Device::readTocPmaAtip( UByteArray& data, int \
format, bool tim  // with these buggy drives.
     // We cannot use this as default since many firmwares fail with a too high data \
length.  //
-    if( (dataLen-4) % descLen || dataLen < 4+descLen ) {
+    if( descLen != 0 && ((dataLen-4) % descLen || dataLen < 4+descLen) ) {
         qDebug() << "(K3b::Device::Device) " << blockDeviceName() << ": READ \
TOC/PMA/ATIP invalid length returned: " << dataLen;  dataLen = 0xFFFF;
     }
@@ -605,7 +603,7 @@ bool K3b::Device::Device::readTocPmaAtip( UByteArray& data, int \
format, bool tim  cmd[8] = data.size();
     if( cmd.transport( TR_DIR_READ, data.data(), data.size() ) == 0 ) {
         dataLen = qMin( dataLen, from2Byte( data.data() ) + 2u );
-        if( (dataLen-4) % descLen || dataLen < 4+descLen ) {
+        if( descLen == 0 || (dataLen-4) % descLen || dataLen < 4+descLen ) {
             // useless length
             data.clear();
             return false;
diff --git a/plugins/project/audiometainforenamer/k3baudiometainforenamerplugin.cpp \
b/plugins/project/audiometainforenamer/k3baudiometainforenamerplugin.cpp index \
                1d67a06..67567c7 100644
--- a/plugins/project/audiometainforenamer/k3baudiometainforenamerplugin.cpp
+++ b/plugins/project/audiometainforenamer/k3baudiometainforenamerplugin.cpp
@@ -46,6 +46,7 @@
 #include <QtWidgets/QToolTip>
 #include <QtWidgets/QTreeWidget>
 #include <QtWidgets/QVBoxLayout>
+#include <QSharedPointer>
 
 #include <taglib/tag.h>
 #include <taglib/fileref.h>
@@ -149,7 +150,8 @@ K3bAudioMetainfoRenamerPluginWidget::K3bAudioMetainfoRenamerPluginWidget( \
                K3b::D
                                         "<em>%n</em> (Track number), and <em>%t</em> \
(Title) "  "are supported.") );
 
-    TagLib::FileRef::addFileTypeResolver( new K3bMimeTypeResolver() );
+    QSharedPointer<K3bMimeTypeResolver> typePtr = \
QSharedPointer<K3bMimeTypeResolver>(new K3bMimeTypeResolver); +    \
TagLib::FileRef::addFileTypeResolver(typePtr.data());  }
 
 
diff --git a/src/k3b.cpp b/src/k3b.cpp
index df34794..5dc6045 100644
--- a/src/k3b.cpp
+++ b/src/k3b.cpp
@@ -288,6 +288,7 @@ void K3b::MainWindow::initActions()
     // need to have all actions in the mainwindow's actioncollection anyway (or am I \
just to stupid to  // see the correct solution?)
 
+    // clang-analyzer wrongly treat KF5's KStandardAction::open as Unix API Improper \
                use of 'open'
     QAction* actionFileOpen = KStandardAction::open( this, SLOT(slotFileOpen()), \
actionCollection() );  actionFileOpen->setToolTip( i18n( "Opens an existing project" \
) );  actionFileOpen->setStatusTip( actionFileOpen->toolTip() );
diff --git a/src/k3bmetaitemmodel.cpp b/src/k3bmetaitemmodel.cpp
index 1cf0259..f3acaeb 100644
--- a/src/k3bmetaitemmodel.cpp
+++ b/src/k3bmetaitemmodel.cpp
@@ -180,6 +180,9 @@ namespace {
 
         // all the node mapping is done on the first col, so make sure we use
         // an index on the first col
+        // 
+        // A valid index belongs to a model, and has non-negative row and column \
numbers +        // so index.model() is NOT nullptr if index.isValid()
         QModelIndex firstColIndex = index.model()->index(index.row(), 0, \
index.parent());  Node* node = findNodeForOriginalIndex( firstColIndex );
         if ( !node ) {
diff --git a/src/misc/k3bmediacopydialog.cpp b/src/misc/k3bmediacopydialog.cpp
index 9281ca6..0269b67 100644
--- a/src/misc/k3bmediacopydialog.cpp
+++ b/src/misc/k3bmediacopydialog.cpp
@@ -300,6 +300,7 @@ void K3b::MediaCopyDialog::slotStartClicked()
                                                     i18n("File Exists"),
                                                     KStandardGuiItem::overwrite() )
                 != KMessageBox::Continue )
+                delete dlg;
                 return;
         }
 
@@ -484,16 +485,17 @@ void K3b::MediaCopyDialog::toggleAll()
             }
             else if ( sourceMedium.diskInfo().mediaType() & \
K3b::Device::MEDIA_DVD_ALL ) {  // only auto for DVD+R(W)
-                if( burnDev->writeCapabilities() & \
                (K3b::Device::MEDIA_DVD_R|K3b::Device::MEDIA_DVD_RW) ) {
-                    modes |= \
                K3b::WritingModeSao|K3b::WritingModeRestrictedOverwrite;
-                    if( burnDev->featureCurrent( \
                K3b::Device::FEATURE_INCREMENTAL_STREAMING_WRITABLE ) != 0 )
-                        modes |= K3b::WritingModeIncrementalSequential;
+                if (burnDev) {
+                    if( burnDev->writeCapabilities() & \
(K3b::Device::MEDIA_DVD_R|K3b::Device::MEDIA_DVD_RW) ) { +                        \
modes |= K3b::WritingModeSao|K3b::WritingModeRestrictedOverwrite; +                   \
if( burnDev->featureCurrent( K3b::Device::FEATURE_INCREMENTAL_STREAMING_WRITABLE ) != \
0 ) +                            modes |= K3b::WritingModeIncrementalSequential;
+                    }
+
+                    // TODO: once we have layer jump support: this is where it goes
+                    //if ( burnDev->supportsWritingMode( \
K3b::Device::WRITING_MODE_LAYER_JUMP ) ) +                    //     modes |= \
K3b::Device::WRITING_MODE_LAYER_JUMP;  }
-
-                // TODO: once we have layer jump support: this is where it goes
-//               if ( burnDev->supportsWritingMode( \
                K3b::Device::WRITING_MODE_LAYER_JUMP ) ) {
-//                   modes |= K3b::Device::WRITING_MODE_LAYER_JUMP;
-//               }
             }
             else if ( sourceMedium.diskInfo().mediaType() & \
K3b::Device::MEDIA_BD_ALL ) {  // no modes, only auto
diff --git a/src/projects/k3baudioprojectmodel.cpp \
b/src/projects/k3baudioprojectmodel.cpp index a9bc3c3..cf4f7e1 100644
--- a/src/projects/k3baudioprojectmodel.cpp
+++ b/src/projects/k3baudioprojectmodel.cpp
@@ -632,7 +632,7 @@ bool K3b::AudioProjectModel::dropMimeData( const QMimeData* data, \
Qt::DropAction  
                 // special case: the source we remove from the track is the last and \
the track  // will be deleted.
-                if( !copyItems && dropTrackAfter == source->track() && \
dropTrackAfter->numberSources() == 1 ) +                if( !copyItems && \
dropTrackAfter == source->track() && dropTrackAfter && \
dropTrackAfter->numberSources() == 1 )  dropTrackAfter = dropTrackAfter->prev();
 
                 if( copyItems )
diff --git a/src/projects/k3bdataurladdingdialog.cpp \
b/src/projects/k3bdataurladdingdialog.cpp index 4dc70da..28986e9 100644
--- a/src/projects/k3bdataurladdingdialog.cpp
+++ b/src/projects/k3bdataurladdingdialog.cpp
@@ -50,6 +50,7 @@
 #include <QtWidgets/QLabel>
 #include <QtWidgets/QLayout>
 #include <QtWidgets/QInputDialog>
+#include <QSharedPointer>
 
 #include <unistd.h>
 
@@ -143,8 +144,8 @@ void K3b::DataUrlAddingDialog::addUrls( const QList<QUrl>& urls,
                                      QWidget* parent )
 {
     if( !urls.isEmpty() ) {
-        K3b::DataUrlAddingDialog* dlg = new K3b::DataUrlAddingDialog( urls, dir, \
                parent );
-        QMetaObject::invokeMethod( dlg, "slotStartAddUrls", Qt::QueuedConnection );
+        QSharedPointer<DataUrlAddingDialog> dlgPtr = \
QSharedPointer<DataUrlAddingDialog>(new DataUrlAddingDialog( urls, dir, parent )); +  \
QMetaObject::invokeMethod( dlgPtr.data(), "slotStartAddUrls", Qt::QueuedConnection ); \
}  }
 
@@ -154,8 +155,8 @@ void K3b::DataUrlAddingDialog::moveItems( const \
QList<K3b::DataItem*>& items,  QWidget* parent )
 {
     if( !items.isEmpty() ) {
-        DataUrlAddingDialog* dlg = new DataUrlAddingDialog( items, dir, false, \
                parent );
-        QMetaObject::invokeMethod( dlg, "slotStartCopyMoveItems", \
Qt::QueuedConnection ); +        QSharedPointer<DataUrlAddingDialog> dlgPtr = \
QSharedPointer<DataUrlAddingDialog>(new DataUrlAddingDialog( items, dir, false, \
parent )); +        QMetaObject::invokeMethod( dlgPtr.data(), \
"slotStartCopyMoveItems", Qt::QueuedConnection );  }
 }
 
@@ -165,8 +166,8 @@ void K3b::DataUrlAddingDialog::copyItems( const \
QList<K3b::DataItem*>& items,  QWidget* parent )
 {
     if( !items.isEmpty() ) {
-        DataUrlAddingDialog* dlg = new DataUrlAddingDialog( items, dir, true, parent \
                );
-        QMetaObject::invokeMethod( dlg, "slotStartCopyMoveItems", \
Qt::QueuedConnection ); +        QSharedPointer<DataUrlAddingDialog> dlgPtr = \
QSharedPointer<DataUrlAddingDialog>(new DataUrlAddingDialog( items, dir, true, parent \
)); +        QMetaObject::invokeMethod( dlgPtr.data(), "slotStartCopyMoveItems", \
Qt::QueuedConnection );  }
 }
 
diff --git a/src/rip/videodvd/k3bvideodvdrippingpreview.cpp \
b/src/rip/videodvd/k3bvideodvdrippingpreview.cpp index af20227..0b51452 100644
--- a/src/rip/videodvd/k3bvideodvdrippingpreview.cpp
+++ b/src/rip/videodvd/k3bvideodvdrippingpreview.cpp
@@ -43,8 +43,10 @@ void K3b::VideoDVDRippingPreview::generatePreview( const \
K3b::VideoDVD::VideoDVD  {
     // cleanup first
     cancel();
-    m_process->deleteLater();
-    m_process = 0;
+    if (m_process) {
+        m_process->deleteLater();
+        m_process = 0;
+    }
     m_tempDir.reset();
     m_canceled = false;
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic