r21967 by craig - Coverity 1396755: Dereference before NULL check

scribus-commit scribus-commit at lists.scribus.net
Sat Apr 22 13:34:28 UTC 2017


Author: craig
Date: Sat Apr 22 13:34:28 2017
New Revision: 21967

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21967
Log:
Coverity 1396755: Dereference before NULL check

Modified:
    trunk/Scribus/scribus/scfonts.cpp

Modified: trunk/Scribus/scribus/scfonts.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21967&path=/trunk/Scribus/scribus/scfonts.cpp
==============================================================================
--- trunk/Scribus/scribus/scfonts.cpp	(original)
+++ trunk/Scribus/scribus/scfonts.cpp	Sat Apr 22 13:34:28 2017
@@ -981,9 +981,19 @@
 	// We currently just need FC_FILE, but other info like font family and style
 	// is available - see "man fontconfig".
 	FcObjectSet* os = FcObjectSetBuild (FC_FILE, (char *) 0);
+	if (!os)
+	{
+		qFatal("SCFonts::AddFontconfigFonts() FcObjectSet* os failed to build object set");
+		return;
+	}
 	// Now ask fontconfig to retrieve info as specified in 'os' about fonts
 	// matching pattern 'pat'.
 	FcFontSet* fs = FcFontList(config, pat, os);
+	if (!fs)
+	{
+		qFatal("SCFonts::AddFontconfigFonts() FcFontSet* fs failed to create font list");
+		return;
+	}
 	FcConfigDestroy(config);
 	FcObjectSetDestroy(os);
 	FcPatternDestroy(pat);
@@ -992,8 +1002,7 @@
 	FT_Library library = NULL;
 	FT_Init_FreeType( &library );
 	// Now iterate over the font files and load them
-	int i;
-	for (i = 0; i < fs->nfont; i++) 
+	for (int i = 0; i < fs->nfont; i++)
 	{
 		FcChar8 *file = NULL;
 		if (FcPatternGetString (fs->fonts[i], FC_FILE, 0, &file) == FcResultMatch)
@@ -1007,8 +1016,7 @@
 				sDebug(QObject::tr("Failed to load a font - freetype2 couldn't find the font file"));
 	}
 	FT_Done_FreeType(library);
-	if (fs)
-		FcFontSetDestroy(fs);
+	FcFontSetDestroy(fs);
 }
 
 #elif defined(Q_OS_LINUX)




More information about the scribus-commit mailing list