Commit 5ecbb51f authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Enable modernize-use-nullptr

parent d9069ef6
Pipeline #15309 passed with stage
in 10 minutes and 24 seconds
......@@ -51,4 +51,4 @@ build_clang_tidy:
- ninja
# Fix the poppler header, remove when debian:unstable ships poppler 0.82 or later
- sed -i "N;N;N;N; s#class MediaRendition\;\nclass MovieAnnotation\;\nclass ScreenAnnotation;#class MediaRendition\;#g" /usr/include/poppler/qt5/poppler-link.h
- "run-clang-tidy -header-filter='.*/okular/.*' -checks='-*,performance-*,bugprone-*,readability-inconsistent-declaration-parameter-name,readability-string-compare,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-make-unique,modernize-make-shared,modernize-use-override,modernize-use-equals-delete,modernize-use-emplace,modernize-loop-convert,-bugprone-macro-parentheses,-bugprone-narrowing-conversions,-bugprone-branch-clone,-bugprone-incorrect-roundings' -config=\"{WarningsAsErrors: '*'}\""
- "run-clang-tidy -header-filter='.*/okular/.*' -checks='-*,performance-*,bugprone-*,readability-inconsistent-declaration-parameter-name,readability-string-compare,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-make-unique,modernize-make-shared,modernize-use-override,modernize-use-equals-delete,modernize-use-emplace,modernize-loop-convert,modernize-use-nullptr,-bugprone-macro-parentheses,-bugprone-narrowing-conversions,-bugprone-branch-clone,-bugprone-incorrect-roundings' -config=\"{WarningsAsErrors: '*'}\""
......@@ -85,7 +85,7 @@ void DocumentTest::testDocdataMigration()
QVERIFY( QFile::copy(KDESRCDIR "data/file1-docdata.xml", docDataPath) );
// Open our document
Okular::Document *m_document = new Okular::Document( 0 );
Okular::Document *m_document = new Okular::Document( nullptr );
QMimeDatabase db;
const QMimeType mime = db.mimeTypeForFile( testFilePath );
QCOMPARE( m_document->openDocument( testFilePath, testFileUrl, mime ), Okular::Document::OpenSuccess );
......
......@@ -1344,7 +1344,7 @@ void PartTest::testSaveAsUndoStackForms_data()
void PartTest::testOpenUrlArguments()
{
QVariantList dummyArgs;
Okular::Part part(NULL, NULL, dummyArgs);
Okular::Part part(nullptr, nullptr, dummyArgs);
KParts::OpenUrlArguments args;
args.setMimeType(QStringLiteral("text/rtf"));
......
......@@ -33,7 +33,7 @@ class ChmGeneratorTest
void ChmGeneratorTest::initTestCase()
{
Okular::SettingsCore::instance( QStringLiteral("ChmGeneratorTest") );
m_document = new Okular::Document( 0 );
m_document = new Okular::Document( nullptr );
const QString testFile = QStringLiteral(KDESRCDIR "autotests/data/test.chm");
QMimeDatabase db;
const QMimeType mime = db.mimeTypeForFile( testFile );
......
......@@ -53,9 +53,9 @@ CHMGenerator::CHMGenerator( QObject *parent, const QVariantList &args )
{
setFeature( TextExtraction );
m_syncGen=0;
m_file=0;
m_request = 0;
m_syncGen=nullptr;
m_file=nullptr;
m_request = nullptr;
}
CHMGenerator::~CHMGenerator()
......@@ -141,7 +141,7 @@ bool CHMGenerator::loadDocument( const QString & fileName, QVector< Okular::Page
{
m_syncGen = new KHTMLPart();
}
disconnect( m_syncGen, 0, this, 0 );
disconnect( m_syncGen, nullptr, this, nullptr );
for (int i = 0; i < m_pageUrl.count(); ++i)
{
......@@ -160,7 +160,7 @@ bool CHMGenerator::doCloseDocument()
{
// delete the document information of the old document
delete m_file;
m_file=0;
m_file=nullptr;
m_textpageAddedList.clear();
m_rectsGenerated.clear();
m_urlPage.clear();
......@@ -217,7 +217,7 @@ void CHMGenerator::slotCompleted()
userMutex()->unlock();
Okular::PixmapRequest *req = m_request;
m_request = 0;
m_request = nullptr;
if ( !req->page()->isBoundingBoxKnown() )
updatePageBoundingBox( req->page()->number(), Okular::Utils::imageBoundingBox( &image ) );
......@@ -391,7 +391,7 @@ void CHMGenerator::additionalRequestData()
new Okular::ObjectRect ( Okular::NormalizedRect(n.getRect(),xScale,yScale),
false,
Okular::ObjectRect::Image,
0));
nullptr));
}
}
}
......
......@@ -60,7 +60,7 @@ extern "C"
ProtocolMSITS::ProtocolMSITS (const QByteArray &pool_socket, const QByteArray &app_socket)
: SlaveBase ("kio_msits", pool_socket, app_socket)
{
m_chmFile = 0;
m_chmFile = nullptr;
}
ProtocolMSITS::~ProtocolMSITS()
......@@ -69,7 +69,7 @@ ProtocolMSITS::~ProtocolMSITS()
return;
chm_close (m_chmFile);
m_chmFile = 0;
m_chmFile = nullptr;
}
// A simple stat() wrapper
......@@ -173,7 +173,7 @@ bool ProtocolMSITS::parseLoadAndLookup ( const QUrl& url, QString& abspath )
// First try to open a temporary file
chmFile * tmpchm;
if( (tmpchm = chm_open ( QFile::encodeName( QDir::toNativeSeparators( filename) ).constData() ) ) == 0 )
if( (tmpchm = chm_open ( QFile::encodeName( QDir::toNativeSeparators( filename) ).constData() ) ) == nullptr )
{
error( KIO::ERR_COULD_NOT_READ, url.toString() );
return false;
......
......@@ -51,7 +51,7 @@ private:
// Resolve an object inside a CHM file
inline bool ResolveObject (const QString& fileName, chmUnitInfo *ui)
{
return m_chmFile != NULL && ::chm_resolve_object(m_chmFile, fileName.toUtf8().constData(), ui) == CHM_RESOLVE_SUCCESS;
return m_chmFile != nullptr && ::chm_resolve_object(m_chmFile, fileName.toUtf8().constData(), ui) == CHM_RESOLVE_SUCCESS;
}
// Retrieve an object from the CHM file
......
......@@ -45,6 +45,6 @@ EBook * EBook::loadFile( const QString &archiveName )
return ebook;
delete ebook;
return 0;
return nullptr;
}
......@@ -43,14 +43,14 @@ EBook_CHM::EBook_CHM()
: EBook()
{
m_envOptions = getenv("KCHMVIEWEROPTS");
m_chmFile = NULL;
m_chmFile = nullptr;
m_filename = m_font = QString();
m_textCodec = 0;
m_textCodecForSpecialFiles = 0;
m_textCodec = nullptr;
m_textCodecForSpecialFiles = nullptr;
m_detectedLCID = 0;
m_currentEncoding = "UTF-8";
m_htmlEntityDecoder = 0;
m_htmlEntityDecoder = nullptr;
}
EBook_CHM::~EBook_CHM()
......@@ -60,20 +60,20 @@ EBook_CHM::~EBook_CHM()
void EBook_CHM::close()
{
if ( m_chmFile == NULL )
if ( m_chmFile == nullptr )
return;
chm_close( m_chmFile );
m_chmFile = NULL;
m_chmFile = nullptr;
m_filename = m_font = QString();
m_home.clear();
m_topicsFile.clear();
m_indexFile.clear();
m_textCodec = 0;
m_textCodecForSpecialFiles = 0;
m_textCodec = nullptr;
m_textCodecForSpecialFiles = nullptr;
m_detectedLCID = 0;
m_currentEncoding = "UTF-8";
}
......@@ -271,14 +271,14 @@ bool EBook_CHM::load(const QString &archiveName)
m_chmFile = chm_open( QFile::encodeName(filename) );
#endif
if ( m_chmFile == NULL )
if ( m_chmFile == nullptr )
return false;
m_filename = filename;
// Reset encoding
m_textCodec = 0;
m_textCodecForSpecialFiles = 0;
m_textCodec = nullptr;
m_textCodecForSpecialFiles = nullptr;
m_currentEncoding = "UTF-8";
// Get information from /#WINDOWS and /#SYSTEM files (encoding, title, context file and so)
......@@ -576,7 +576,7 @@ bool EBook_CHM::parseFileAndFillArray( const QString& file, QList< ParsedEntry >
bool EBook_CHM::ResolveObject(const QString& fileName, chmUnitInfo *ui) const
{
return m_chmFile != NULL
return m_chmFile != nullptr
&& ::chm_resolve_object(m_chmFile, qPrintable( fileName ), ui) ==
CHM_RESOLVE_SUCCESS;
}
......@@ -586,7 +586,7 @@ bool EBook_CHM::hasFile(const QString & fileName) const
{
chmUnitInfo ui;
return m_chmFile != NULL
return m_chmFile != nullptr
&& ::chm_resolve_object(m_chmFile, qPrintable( fileName ), &ui) ==
CHM_RESOLVE_SUCCESS;
}
......@@ -680,7 +680,7 @@ bool EBook_CHM::getInfoFromSystem()
chmUnitInfo ui;
int index = 0;
unsigned char* cursor = NULL, *p;
unsigned char* cursor = nullptr, *p;
unsigned short value = 0;
long size = 0;
......
......@@ -289,7 +289,7 @@ static const EbookChmTextEncodingEntry text_encoding_table [] =
lcid_Western
},
{ 0, 0 }
{ nullptr, nullptr }
};
......
......@@ -35,7 +35,7 @@ static const char * URL_SCHEME_EPUB = "epub";
EBook_EPUB::EBook_EPUB()
: EBook()
{
m_zipFile = 0;
m_zipFile = nullptr;
}
EBook_EPUB::~EBook_EPUB()
......@@ -88,7 +88,7 @@ void EBook_EPUB::close()
if ( m_zipFile )
{
zip_close( m_zipFile );
m_zipFile = 0;
m_zipFile = nullptr;
}
//if ( m_epubFile.isOpen() )
......@@ -322,7 +322,7 @@ bool EBook_EPUB::getFileAsString(QString &str, const QString &path) const
if ( utf16 > 0 && utf16 < endxmltag )
{
QMessageBox::critical( 0,
QMessageBox::critical( nullptr,
("Unsupported encoding"),
("The encoding of this ebook is not supported yet. Please send it to gyunaev@ulduzsoft.com for support to be added") );
return false;
......
......@@ -71,7 +71,7 @@ class SearchDataKeeper
EBookSearch::EBookSearch()
{
m_Index = 0;
m_Index = nullptr;
}
......@@ -122,7 +122,7 @@ bool EBookSearch::generateIndex( EBook * ebookFile, QDataStream & stream )
if ( !m_Index->makeIndex( documents, ebookFile ) )
{
delete m_Index;
m_Index = 0;
m_Index = nullptr;
return false;
}
......@@ -221,5 +221,5 @@ bool EBookSearch::searchQuery(const QString & query, QList< QUrl > * results, EB
bool EBookSearch::hasIndex() const
{
return m_Index != 0;
return m_Index != nullptr;
}
......@@ -29,10 +29,10 @@ class HelperEntityDecoder
{
public:
// Initialization with the specific decoder
HelperEntityDecoder( QTextCodec * encoder = 0 );
HelperEntityDecoder( QTextCodec * encoder = nullptr );
// Used when the encoding changes
void changeEncoding( QTextCodec * encoder = 0 );
void changeEncoding( QTextCodec * encoder = nullptr );
// The decoder function
QString decode( const QString& entity ) const;
......
......@@ -62,7 +62,7 @@ QDataStream &operator<<( QDataStream &s, const Document &l )
}
Index::Index()
: QObject( 0 )
: QObject( nullptr )
{
lastWindowClosed = false;
connect( qApp, SIGNAL( lastWindowClosed() ), this, SLOT( setLastWinClosed() ) );
......@@ -121,7 +121,7 @@ bool Index::makeIndex(const QList< QUrl >& docs, EBook *chmFile )
void Index::insertInDict( const QString &str, int docNum )
{
Entry *e = 0;
Entry *e = nullptr;
if ( dict.count() )
e = dict[ str ];
......@@ -364,7 +364,7 @@ QList< QUrl > Index::query(const QStringList &terms, const QStringList &termSeq,
QStringList::ConstIterator it = terms.begin();
for ( it = terms.begin(); it != terms.end(); ++it )
{
Entry *e = 0;
Entry *e = nullptr;
if ( dict[ *it ] )
{
......
......@@ -33,7 +33,7 @@ class EpubGeneratorTest
void EpubGeneratorTest::initTestCase()
{
Okular::SettingsCore::instance( QStringLiteral("EpubGeneratorTest") );
m_document = new Okular::Document( 0 );
m_document = new Okular::Document( nullptr );
const QString testFile = QStringLiteral(KDESRCDIR "autotests/data/test.epub");
QMimeDatabase db;
const QMimeType mime = db.mimeTypeForFile( testFile );
......
......@@ -28,7 +28,7 @@
using namespace Epub;
Converter::Converter() : mTextDocument(NULL)
Converter::Converter() : mTextDocument(nullptr)
{
}
......@@ -170,7 +170,7 @@ QTextDocument* Converter::convert( const QString &fileName )
if (!newDocument->isValid()) {
emit error(i18n("Error while opening the EPub document."), -1);
delete newDocument;
return NULL;
return nullptr;
}
mTextDocument = newDocument;
......@@ -379,7 +379,7 @@ QTextDocument* Converter::convert( const QString &fileName )
if (mSectionMap.contains(link)) {
block = mSectionMap.value(link);
} else { // load missing resource
char *data = 0;
char *data = nullptr;
//epub_get_data can't handle whitespace url encodings
QByteArray ba = link.replace(QLatin1String("%20"), QLatin1String(" ")).toLatin1();
const char *clinkClean = ba.data();
......
......@@ -87,7 +87,7 @@ QTextDocument *Converter::convertOpenFile()
flags |= MKD_NOPANTS;
if ( !mkd_compile( markdownHandle, flags ) ) {
emit error( i18n( "Failed to compile the Markdown document." ), -1 );
return 0;
return nullptr;
}
char *htmlDocument;
......
......@@ -52,12 +52,12 @@ QTextDocument* Converter::convert( const QString &fileName )
if (!newDocument->mobi()->isValid()) {
emit error(i18n("Error while opening the Mobipocket document."), -1);
delete newDocument;
return NULL;
return nullptr;
}
if (newDocument->mobi()->hasDRM()) {
emit error(i18n("This book is protected by DRM and can be displayed only on designated device"), -1);
delete newDocument;
return NULL;
return nullptr;
}
handleMetadata(newDocument->mobi()->metadata());
......
......@@ -49,7 +49,7 @@
#define SEGMENT_END_CHAR ']'
#define OPTION_SEPARATOR_CHARS "=:"
HashTable *SectionsTable = NULL;
HashTable *SectionsTable = nullptr;
static HashTable* GetOrCreateSegment
(
......@@ -58,10 +58,10 @@ static HashTable* GetOrCreateSegment
{
HashTable* target;
if (SectionsTable == NULL)
if (SectionsTable == nullptr)
SectionsTable = _plkr_NewHashTable (23);
if ((target = (HashTable*)_plkr_FindInTable (SectionsTable, name)) == NULL) {
if ((target = (HashTable*)_plkr_FindInTable (SectionsTable, name)) == nullptr) {
target = _plkr_NewHashTable (53);
_plkr_AddToTable (SectionsTable, name, target);
}
......@@ -74,7 +74,7 @@ static int ReadConfigFile
const char* filename
)
{
HashTable* current_segment = NULL;
HashTable* current_segment = nullptr;
FILE* fp = fopen (filename, "r");
char* ptr;
char* str_end;
......@@ -89,13 +89,13 @@ static int ReadConfigFile
int status;
int line_number;
if (fp == NULL) {
if (fp == nullptr) {
_plkr_message ("Can't open config file %s", filename);
return 0;
}
current_segment = GetOrCreateSegment ("default");
current_option = NULL;
current_option = nullptr;
status = 1; /* optimistic */
line_number = 0;
......@@ -103,7 +103,7 @@ static int ReadConfigFile
while (true) {
ptr = fgets (linebuf, sizeof (linebuf) - 1, fp);
if (ptr == NULL)
if (ptr == nullptr)
break;
line_number += 1;
......@@ -122,7 +122,7 @@ static int ReadConfigFile
/* blank line */
continue;
if ((strchr (COMMENT_CHARS, linebuf[0]) != NULL) ||
if ((strchr (COMMENT_CHARS, linebuf[0]) != nullptr) ||
(strncmp (linebuf, "rem", 3) == 0) ||
(strncmp (linebuf, "REM", 3) == 0))
/* comment */
......@@ -133,7 +133,7 @@ static int ReadConfigFile
if (linebuf[buf_index] == SEGMENT_LEAD_CHAR) {
if ((str_end =
strchr (linebuf + buf_index + 1,
SEGMENT_END_CHAR)) == NULL) {
SEGMENT_END_CHAR)) == nullptr) {
/* invalid segment line */
_plkr_message ("%s:%d: Invalid segment line '%s'",
filename, line_number, linebuf);
......@@ -147,11 +147,11 @@ static int ReadConfigFile
/* fprintf (stderr, "Current segment is now %p (%s)\n", current_segment, str_begin); */
if (current_option)
free (current_option);
current_option = NULL;
current_option = nullptr;
}
else if ((linebuf[0] == ' ' || linebuf[0] == '\t')
&& current_option != NULL) {
&& current_option != nullptr) {
/* continuation line */
str_begin =
(char *) _plkr_RemoveFromTable (current_segment,
......@@ -190,7 +190,7 @@ static int ReadConfigFile
while (isspace (*ptr) && (*ptr != '\0'))
ptr++;
if (strchr (OPTION_SEPARATOR_CHARS, *ptr) != NULL)
if (strchr (OPTION_SEPARATOR_CHARS, *ptr) != nullptr)
ptr++;
else {
_plkr_message ("%s:%d: Invalid option line '%s'",
......@@ -251,7 +251,7 @@ static void TryReadConfigFile
{
char* filename;
if (dir == NULL || name == NULL)
if (dir == nullptr || name == nullptr)
return;
filename = (char *) malloc (strlen (dir) + strlen (name) + 2);
......@@ -272,7 +272,7 @@ static void InitializeConfigInfo ()
char *home = getenv ("HOME");
TryReadConfigFile (config_dir, system_config_file_name);
if (home != NULL)
if (home != nullptr)
TryReadConfigFile (home, user_config_filename);
}
......@@ -283,38 +283,38 @@ char* plkr_GetConfigString
char* default_value
)
{
char* value = NULL;
char* value = nullptr;
HashTable* section;
if (SectionsTable == NULL)
if (SectionsTable == nullptr)
InitializeConfigInfo ();
if (SectionsTable == NULL)
if (SectionsTable == nullptr)
return default_value;
if (section_name != NULL) {
if (section_name != nullptr) {
if ((section =
(HashTable *) _plkr_FindInTable (SectionsTable,
section_name)) != NULL)
section_name)) != nullptr)
value = (char *) _plkr_FindInTable (section, option_name);
}
if (value == NULL && ((section_name == NULL)
if (value == nullptr && ((section_name == nullptr)
|| (strcmp (section_name, "default") != 0))) {
if ((section =
(HashTable *) _plkr_FindInTable (SectionsTable,
STRINGIFY (OS_SECTION_NAME)))
!= NULL)
!= nullptr)
value = (char *) _plkr_FindInTable (section, option_name);
}
if (value == NULL && ((section_name == NULL)
if (value == nullptr && ((section_name == nullptr)
|| (strcmp (section_name, "default") != 0))) {
if ((section =
(HashTable *) _plkr_FindInTable (SectionsTable,
"default")) != NULL)
"default")) != nullptr)
value = (char *) _plkr_FindInTable (section, option_name);
}
return ((value == NULL) ? default_value : value);
return ((value == nullptr) ? default_value : value);
}
long int plkr_GetConfigInt
......@@ -324,11 +324,11 @@ long int plkr_GetConfigInt
long int default_value
)
{
char* svalue = plkr_GetConfigString (section_name, option_name, NULL);
char* svalue = plkr_GetConfigString (section_name, option_name, nullptr);
char* endptr;
long int value;
if (svalue == NULL)
if (svalue == nullptr)
return default_value;
value = strtol (svalue, &endptr, 0);
......@@ -349,11 +349,11 @@ double plkr_GetConfigFloat
double default_value
)
{
char* svalue = plkr_GetConfigString (section_name, option_name, NULL);
char* svalue = plkr_GetConfigString (section_name, option_name, nullptr);
char* endptr;
double value;
if (svalue == NULL)
if (svalue == nullptr)
return default_value;
value = strtod (svalue, &endptr);
......@@ -374,9 +374,9 @@ int plkr_GetConfigBoolean
int default_value
)
{
char* svalue = plkr_GetConfigString (section_name, option_name, NULL);
char* svalue = plkr_GetConfigString (section_name, option_name, nullptr);
if (svalue == NULL)
if (svalue == nullptr)
return default_value;
if ((strcmp (svalue, "1") == 0) ||
......
......@@ -232,7 +232,7 @@ bool TranscribePalmImageToJPEG
imagedatastart = palmimage + 16;
}
else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) {
colormap = NULL;
colormap = nullptr;
palm_red_bits = palmimage[16];
palm_green_bits = palmimage[17];
palm_blue_bits = palmimage[18];
......@@ -406,13 +406,13 @@ bool TranscribeMultiImageRecord
unsigned char* bytes
)
{
unsigned char* pbytes = 0;
unsigned char* outbytes = 0;
unsigned char* outptr = 0;
unsigned char* pbytes = nullptr;
unsigned char* outbytes = nullptr;
unsigned char* outptr = nullptr;
unsigned char* ptr = &bytes[12];
plkr_DataRecordType ptype;
PALMPIX* cells = 0;
PALMPIX* acell = 0;
PALMPIX* cells = nullptr;
PALMPIX* acell = nullptr;