r23761 by jghali - Fix coverity 1426969: Unchecked dynamic_cast

scribus-commit scribus-commit at lists.scribus.net
Mon May 11 13:48:05 UTC 2020


Author: jghali
Date: Mon May 11 13:48:05 2020
New Revision: 23761

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23761
Log:
Fix coverity 1426969: Unchecked dynamic_cast

Modified:
    trunk/Scribus/scribus/ui/outlinepalette.cpp
    trunk/Scribus/scribus/ui/outlinepalette.h

Modified: trunk/Scribus/scribus/ui/outlinepalette.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23761&path=/trunk/Scribus/scribus/ui/outlinepalette.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/outlinepalette.cpp	(original)
+++ trunk/Scribus/scribus/ui/outlinepalette.cpp	Mon May 11 13:48:05 2020
@@ -701,78 +701,68 @@
 	connect(reportDisplay, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotDoRename(QTreeWidgetItem*, int)));
 }
 
-QTreeWidgetItem* OutlinePalette::getListItem(int SNr, PageItem *Nr)
+QTreeWidgetItem* OutlinePalette::getListItem(int pageNr, PageItem *pageItem)
 {
 	OutlineTreeItem *item = nullptr;
 	QTreeWidgetItem *retVal = nullptr;
 	if (currDoc->masterPageMode())
 	{
-		if (Nr == nullptr)
-		{
-			QTreeWidgetItemIterator it( reportDisplay );
-			while ( (*it) )
+		if (pageItem == nullptr)
+		{
+			for (QTreeWidgetItemIterator it(reportDisplay); *it; ++it)
 			{
 				item = dynamic_cast<OutlineTreeItem*>(*it);
-				if ((item->type == 0) && (item->PageObject->pageNr() == SNr))
+				if (item && (item->type == 0) && (item->PageObject->pageNr() == pageNr))
 				{
 					retVal = (*it);
 					break;
 				}
-				++it;
 			}
 		}
 		else
 		{
-			QTreeWidgetItemIterator it( reportDisplay );
-			while ( (*it) )
+			for (QTreeWidgetItemIterator it(reportDisplay); *it; ++it)
 			{
 				item = dynamic_cast<OutlineTreeItem*>(*it);
-				if ((item->type == 1) && (item->PageItemObject == Nr))
+				if (item && (item->type == 1) && (item->PageItemObject == pageItem))
 				{
 					retVal = (*it);
 					break;
 				}
-				++it;
 			}
 		}
 	}
 	else
 	{
-		if (Nr == nullptr)
-		{
-			QTreeWidgetItemIterator it( reportDisplay );
-			while ( (*it) )
+		if (pageItem == nullptr)
+		{
+			for (QTreeWidgetItemIterator it(reportDisplay); *it; ++it)
 			{
 				item = dynamic_cast<OutlineTreeItem*>(*it);
-				if (!item)
-					qFatal("OutlinePalette::getListItem !item");
-				if ((item->type == 2) && (item->PageObject->pageNr() == SNr))
+				if (item && (item->type == 2) && (item->PageObject->pageNr() == pageNr))
 				{
 					retVal = (*it);
 					break;
 				}
-				++it;
 			}
 		}
 		else
 		{
-			QTreeWidgetItemIterator it( reportDisplay );
-			while ( (*it) )
+			for (QTreeWidgetItemIterator it(reportDisplay); *it; ++it)
 			{
 				item = dynamic_cast<OutlineTreeItem*>(*it);
-				if (((item->type == 3) || (item->type == 4)) && (item->PageItemObject == Nr))
+				if (item && ((item->type == 3) || (item->type == 4)) && (item->PageItemObject == pageItem))
 				{
 					retVal = (*it);
 					break;
 				}
-				++it;
 			}
 		}
 	}
 	return retVal;
 }
 
-void OutlinePalette::slotShowSelect(int SNr, PageItem *Nr)
+void OutlinePalette::slotShowSelect(int pageNr, PageItem *pageItem)
 {
 	if (!m_MainWindow || m_MainWindow->scriptIsRunning())
 		return;
@@ -799,7 +789,7 @@
 	}
 	else
 	{
-		QTreeWidgetItem *retVal = getListItem(SNr, Nr);
+		QTreeWidgetItem *retVal = getListItem(pageNr, pageItem);
 		if (retVal != nullptr && !retVal->isHidden())
 			retVal->setSelected(true);
 	}

Modified: trunk/Scribus/scribus/ui/outlinepalette.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23761&path=/trunk/Scribus/scribus/ui/outlinepalette.h
==============================================================================
--- trunk/Scribus/scribus/ui/outlinepalette.h	(original)
+++ trunk/Scribus/scribus/ui/outlinepalette.h	Mon May 11 13:48:05 2020
@@ -67,7 +67,7 @@
 	void setDoc(ScribusDoc *);
 	void unsetDoc();
 	void reopenTree();
-	QTreeWidgetItem* getListItem(int SNr, PageItem *Nr);
+	QTreeWidgetItem* getListItem(int pageNr, PageItem *pageItem);
 	void setItemIcon(QTreeWidgetItem *item, PageItem *pgItem);
 	void parseSubGroup(OutlineTreeItem* object, QList<PageItem*> *subGroupList, int itemType, ScPage *a);
 	void buildReopenVals();
@@ -77,7 +77,7 @@
 	void filterTree(const QString& keyword);
 	void iconSetChange();
 	void languageChange();
-	void slotShowSelect(int SNr, PageItem *Nr);
+	void slotShowSelect(int pageNr, PageItem *pageItem);
 	void setPaletteShown(bool);
 	void slotRightClick(QPoint point);
 	void setActiveLayer(int layerID);




More information about the scribus-commit mailing list