r21993 by craig - Coverity 1350070: Unchecked file open return value

scribus-commit scribus-commit at lists.scribus.net
Sun Apr 23 10:15:52 UTC 2017


Author: craig
Date: Sun Apr 23 10:15:52 2017
New Revision: 21993

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21993
Log:
Coverity 1350070: Unchecked file open return value

Modified:
    trunk/Scribus/scribus/plugins/newfromtemplateplugin/nfttemplate.cpp

Modified: trunk/Scribus/scribus/plugins/newfromtemplateplugin/nfttemplate.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21993&path=/trunk/Scribus/scribus/plugins/newfromtemplateplugin/nfttemplate.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/newfromtemplateplugin/nfttemplate.cpp	(original)
+++ trunk/Scribus/scribus/plugins/newfromtemplateplugin/nfttemplate.cpp	Sun Apr 23 10:15:52 2017
@@ -21,56 +21,58 @@
 
 void nfttemplate::remove()
 {
-	if (tmplXml->exists())
+	if (!tmplXml->exists())
+		return;
+	if(!tmplXml->open(QIODevice::ReadOnly))
+		return;
+	QString newTmplXml;
+	QString tmp;
+	bool collect = false;
+	QTextStream stream(tmplXml);
+	stream.setCodec("UTF-8");
+	QString line = stream.readLine();
+	while (!line.isNull())
 	{
-		QString newTmplXml = "";
-		QString tmp;
-		bool collect = false;
-		tmplXml->open(QIODevice::ReadOnly);
-		QTextStream stream(tmplXml);
-		stream.setCodec("UTF-8");
-		QString line = stream.readLine();
-		while (!line.isNull())
+		if ((line.indexOf(enCategory) != -1) || collect)
 		{
-			if ((line.indexOf(enCategory) != -1) || collect)
+			collect = true;
+			line += "\n";
+			tmp += line;
+			if (line.indexOf("name") != -1)
 			{
-				collect = true;
-				line += "\n";
-				tmp += line;
-				if (line.indexOf("name") != -1)
-				{
-					if (line.indexOf(name) == -1)
-					{
-						collect = false;
-						newTmplXml += tmp;
-						tmp = "";
-					}
-				} 
-				else if (line.indexOf("file") != -1)
-				{
-					QString shortFile = file.right(file.length() - file.lastIndexOf("/") -1);
-					if (line.indexOf(shortFile) == -1)
-					{
-						collect = false;
-						newTmplXml += tmp;
-						tmp = "";
-					}
-				} 
-				else if (line.indexOf("</template>") != -1)
+				if (line.indexOf(name) == -1)
 				{
 					collect = false;
+					newTmplXml += tmp;
 					tmp = "";
 				}
 			}
-			else
+			else if (line.indexOf("file") != -1)
 			{
-				line += "\n";
-				newTmplXml += line;
+				QString shortFile = file.right(file.length() - file.lastIndexOf("/") -1);
+				if (line.indexOf(shortFile) == -1)
+				{
+					collect = false;
+					newTmplXml += tmp;
+					tmp = "";
+				}
 			}
-			line = stream.readLine();
+			else if (line.indexOf("</template>") != -1)
+			{
+				collect = false;
+				tmp = "";
+			}
 		}
-		tmplXml->close();
-		tmplXml->open(QIODevice::WriteOnly);
+		else
+		{
+			line += "\n";
+			newTmplXml += line;
+		}
+		line = stream.readLine();
+	}
+	tmplXml->close();
+	if (tmplXml->open(QIODevice::WriteOnly))
+	{
 		QTextStream instream(tmplXml);
 		instream.setCodec("UTF-8");
 		instream << newTmplXml;




More information about the scribus-commit mailing list