Commit e428033c authored by Albert Astals Cid's avatar Albert Astals Cid

Run clang-tidy with modernize nullptr

Also add two enum values in the qt5 frontend to representate no flags
Also mark glib/gtk/cairo system includes so that gcc doesn't report the issues in those headers
parent 2e478876
......@@ -111,6 +111,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(_warn "${_warn} -Woverloaded-virtual")
set(_warn "${_warn} -Wmissing-declarations")
set(_warn "${_warn} -Wundef")
set(_warn "${_warn} -Wzero-as-null-pointer-constant")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0")
set(_warn "${_warn} -Wsuggest-override")
endif()
......@@ -119,7 +120,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(_warnx "${_warnx} -Wconversion")
set(_warnx "${_warnx} -Wshadow")
set(_warnx "${_warnx} -Wuseless-cast")
set(_warnx "${_warnx} -Wzero-as-null-pointer-constant")
set(DEFAULT_COMPILE_WARNINGS "${_warn}")
set(DEFAULT_COMPILE_WARNINGS_EXTRA "${_warn} ${_warnx}")
......
......@@ -47,7 +47,7 @@ initer::initer()
{
if (!count) {
globalParams = new GlobalParams();
setErrorCallback(detail::error_function, NULL);
setErrorCallback(detail::error_function, nullptr);
}
count++;
}
......@@ -58,7 +58,7 @@ initer::~initer()
--count;
if (!count) {
delete globalParams;
globalParams = 0;
globalParams = nullptr;
}
}
}
......@@ -67,8 +67,8 @@ initer::~initer()
document_private::document_private(GooString *file_path, const std::string &owner_password,
const std::string &user_password)
: initer()
, doc(0)
, raw_doc_data(0)
, doc(nullptr)
, raw_doc_data(nullptr)
, raw_doc_data_length(0)
, is_locked(false)
{
......@@ -81,8 +81,8 @@ document_private::document_private(byte_array *file_data,
const std::string &owner_password,
const std::string &user_password)
: initer()
, doc(0)
, raw_doc_data(0)
, doc(nullptr)
, raw_doc_data(nullptr)
, raw_doc_data_length(0)
, is_locked(false)
{
......@@ -97,7 +97,7 @@ document_private::document_private(const char *file_data, int file_data_length,
const std::string &owner_password,
const std::string &user_password)
: initer()
, doc(0)
, doc(nullptr)
, raw_doc_data(file_data)
, raw_doc_data_length(file_data_length)
, is_locked(false)
......@@ -129,7 +129,7 @@ document* document_private::check_document(document_private *doc, byte_array *fi
}
delete doc;
}
return 0;
return nullptr;
}
/**
......@@ -204,7 +204,7 @@ bool document::is_locked() const
bool document::unlock(const std::string &owner_password, const std::string &user_password)
{
if (d->is_locked) {
document_private *newdoc = 0;
document_private *newdoc = nullptr;
if (d->doc_data.size() > 0) {
newdoc = new document_private(&d->doc_data,
owner_password, user_password);
......@@ -360,7 +360,7 @@ bool document::set_info_key(const std::string &key, const ustring &val)
GooString *goo_val;
if (val.empty()) {
goo_val = NULL;
goo_val = nullptr;
} else {
goo_val = detail::ustring_to_unicode_GooString(val);
}
......@@ -406,7 +406,7 @@ bool document::set_info_date(const std::string &key, time_type val)
GooString *goo_date;
if (val == time_type(-1)) {
goo_date = NULL;
goo_date = nullptr;
} else {
time_t t = static_cast<time_t> (val);
goo_date = timeToDateString(&t);
......@@ -451,7 +451,7 @@ bool document::set_title(const ustring &title)
GooString *goo_title;
if (title.empty()) {
goo_title = NULL;
goo_title = nullptr;
} else {
goo_title = detail::ustring_to_unicode_GooString(title);
}
......@@ -495,7 +495,7 @@ bool document::set_author(const ustring &author)
GooString *goo_author;
if (author.empty()) {
goo_author = NULL;
goo_author = nullptr;
} else {
goo_author = detail::ustring_to_unicode_GooString(author);
}
......@@ -539,7 +539,7 @@ bool document::set_subject(const ustring &subject)
GooString *goo_subject;
if (subject.empty()) {
goo_subject = NULL;
goo_subject = nullptr;
} else {
goo_subject = detail::ustring_to_unicode_GooString(subject);
}
......@@ -583,7 +583,7 @@ bool document::set_keywords(const ustring &keywords)
GooString *goo_keywords;
if (keywords.empty()) {
goo_keywords = NULL;
goo_keywords = nullptr;
} else {
goo_keywords = detail::ustring_to_unicode_GooString(keywords);
}
......@@ -627,7 +627,7 @@ bool document::set_creator(const ustring &creator)
GooString *goo_creator;
if (creator.empty()) {
goo_creator = NULL;
goo_creator = nullptr;
} else {
goo_creator = detail::ustring_to_unicode_GooString(creator);
}
......@@ -671,7 +671,7 @@ bool document::set_producer(const ustring &producer)
GooString *goo_producer;
if (producer.empty()) {
goo_producer = NULL;
goo_producer = nullptr;
} else {
goo_producer = detail::ustring_to_unicode_GooString(producer);
}
......@@ -715,7 +715,7 @@ bool document::set_creation_date(time_type creation_date)
GooString *goo_creation_date;
if (creation_date == time_type(-1)) {
goo_creation_date = NULL;
goo_creation_date = nullptr;
} else {
time_t t = static_cast<time_t> (creation_date);
goo_creation_date = timeToDateString(&t);
......@@ -760,7 +760,7 @@ bool document::set_modification_date(time_type mod_date)
GooString *goo_mod_date;
if (mod_date == time_type(-1)) {
goo_mod_date = NULL;
goo_mod_date = nullptr;
} else {
time_t t = static_cast<time_t> (mod_date);
goo_mod_date = timeToDateString(&t);
......@@ -858,7 +858,7 @@ bool document::get_pdf_id(std::string *permanent_id, std::string *update_id) con
GooString goo_permanent_id;
GooString goo_update_id;
if (!d->doc->getID(permanent_id ? &goo_permanent_id : 0, update_id ? &goo_update_id : 0)) {
if (!d->doc->getID(permanent_id ? &goo_permanent_id : nullptr, update_id ? &goo_update_id : nullptr)) {
return false;
}
......@@ -896,7 +896,7 @@ page* document::create_page(const ustring &label) const
int index = 0;
if (!d->doc->getCatalog()->labelToIndex(goolabel.get(), &index)) {
return 0;
return nullptr;
}
return create_page(index);
}
......@@ -1047,7 +1047,7 @@ document* document::load_from_file(const std::string &file_name,
document_private *doc = new document_private(
new GooString(file_name.c_str()),
owner_password, user_password);
return document_private::check_document(doc, 0);
return document_private::check_document(doc, nullptr);
}
/**
......@@ -1065,7 +1065,7 @@ document* document::load_from_data(byte_array *file_data,
const std::string &user_password)
{
if (!file_data || file_data->size() < 10) {
return 0;
return nullptr;
}
document_private *doc = new document_private(
......@@ -1093,11 +1093,11 @@ document* document::load_from_raw_data(const char *file_data,
const std::string &user_password)
{
if (!file_data || file_data_length < 10) {
return 0;
return nullptr;
}
document_private *doc = new document_private(
file_data, file_data_length,
owner_password, user_password);
return document_private::check_document(doc, 0);
return document_private::check_document(doc, nullptr);
}
......@@ -52,7 +52,7 @@ struct FileCloser {
FileCloser(const FileCloser &) = delete;
FileCloser& operator=(const FileCloser &) = delete;
inline bool close()
{ if (f) { const int c = fclose(f); f = 0; return c == 0; } return true; }
{ if (f) { const int c = fclose(f); f = nullptr; return c == 0; } return true; }
FILE *f;
};
......@@ -91,7 +91,7 @@ using namespace poppler;
image_private::image_private(int iwidth, int iheight, image::format_enum iformat)
: ref(1)
, data(0)
, data(nullptr)
, width(iwidth)
, height(iheight)
, bytes_per_row(0)
......@@ -111,19 +111,19 @@ image_private::~image_private()
image_private *image_private::create_data(int width, int height, image::format_enum format)
{
if (width <= 0 || height <= 0) {
return 0;
return nullptr;
}
int bpr = calc_bytes_per_row(width, format);
if (bpr <= 0) {
return 0;
return nullptr;
}
std::unique_ptr<image_private> d(new image_private(width, height, format));
d->bytes_num = bpr * height;
d->data = reinterpret_cast<char *>(std::malloc(d->bytes_num));
if (!d->data) {
return 0;
return nullptr;
}
d->own_data = true;
d->bytes_per_row = bpr;
......@@ -134,12 +134,12 @@ image_private *image_private::create_data(int width, int height, image::format_e
image_private *image_private::create_data(char *data, int width, int height, image::format_enum format)
{
if (width <= 0 || height <= 0 || !data) {
return 0;
return nullptr;
}
int bpr = calc_bytes_per_row(width, format);
if (bpr <= 0) {
return 0;
return nullptr;
}
image_private *d = new image_private(width, height, format);
......@@ -175,7 +175,7 @@ image_private *image_private::create_data(char *data, int width, int height, ima
Construct an invalid image.
*/
image::image()
: d(0)
: d(nullptr)
{
}
......@@ -283,7 +283,7 @@ int image::bytes_per_row() const
char *image::data()
{
if (!d) {
return 0;
return nullptr;
}
detach();
......@@ -299,7 +299,7 @@ char *image::data()
*/
const char *image::const_data() const
{
return d ? d->data : 0;
return d ? d->data : nullptr;
}
/**
......
......@@ -37,7 +37,7 @@ page_private::page_private(document_private *_doc, int _index)
: doc(_doc)
, page(doc->doc->getCatalog()->getPage(_index + 1))
, index(_index)
, transition(0)
, transition(nullptr)
{
}
......@@ -127,7 +127,7 @@ double page::duration() const
*/
rectf page::page_rect(page_box_enum box) const
{
PDFRectangle *r = 0;
PDFRectangle *r = nullptr;
switch (box) {
case media_box:
r = d->page->getMediaBox();
......@@ -211,7 +211,7 @@ bool page::search(const ustring &text, rectf &r, search_direction_enum direction
double rect_right = r.right();
double rect_bottom = r.bottom();
TextOutputDev td(NULL, gTrue, 0, gFalse, gFalse);
TextOutputDev td(nullptr, gTrue, 0, gFalse, gFalse);
d->doc->doc->displayPage(&td, d->index + 1, 72, 72, rotation_value, false, true, false);
TextPage *text_page = td.takeText();
......@@ -270,7 +270,7 @@ ustring page::text(const rectf &r, text_layout_enum layout_mode) const
{
std::unique_ptr<GooString> s;
const GBool use_raw_order = (layout_mode == raw_order_layout);
TextOutputDev td(0, gFalse, 0, use_raw_order, gFalse);
TextOutputDev td(nullptr, gFalse, 0, use_raw_order, gFalse);
d->doc->doc->displayPage(&td, d->index + 1, 72, 72, 0, false, true, false);
if (r.is_empty()) {
PDFRectangle *rect = d->page->getCropBox();
......
......@@ -37,7 +37,7 @@ static void stderr_debug_function(const std::string &msg, void * /*data*/)
}
debug_func detail::user_debug_function = stderr_debug_function;
void *detail::debug_closure = 0;
void *detail::debug_closure = nullptr;
void detail::error_function(void * /*data*/, ErrorCategory /*category*/, Goffset pos, char *msg)
{
......
......@@ -37,12 +37,12 @@ toc_private::~toc_private()
toc* toc_private::load_from_outline(Outline *outline)
{
if (!outline) {
return 0;
return nullptr;
}
GooList *items = outline->getItems();
if (!items || items->getLength() < 1) {
return 0;
return nullptr;
}
toc *newtoc = new toc();
......
......@@ -75,7 +75,7 @@ static const ArgDesc the_args[] = {
"print usage information" },
{ "--help", argFlag, &show_help, 0,
"print usage information" },
{ NULL, argFlag, 0, 0, NULL }
{ nullptr, argFlag, nullptr, 0, nullptr }
};
static void error(const std::string &msg)
......
......@@ -44,7 +44,7 @@ static const ArgDesc the_args[] = {
"print usage information" },
{ "--help", argFlag, &show_help, 0,
"print usage information" },
{ NULL, argFlag, 0, 0, NULL }
{ nullptr, argFlag, nullptr, 0, nullptr }
};
static void error(const std::string &msg)
......
......@@ -57,29 +57,29 @@ char *FoFiBase::readFile(char *fileName, int *fileLen) {
if (!(f = fopen(fileName, "rb"))) {
error(errIO, -1, "Cannot open '{0:s}'", fileName);
return NULL;
return nullptr;
}
if (fseek(f, 0, SEEK_END) != 0) {
error(errIO, -1, "Cannot seek to end of '{0:s}'", fileName);
fclose(f);
return NULL;
return nullptr;
}
n = (int)ftell(f);
if (n < 0) {
error(errIO, -1, "Cannot determine length of '{0:s}'", fileName);
fclose(f);
return NULL;
return nullptr;
}
if (fseek(f, 0, SEEK_SET) != 0) {
error(errIO, -1, "Cannot seek to start of '{0:s}'", fileName);
fclose(f);
return NULL;
return nullptr;
}
buf = (char *)gmalloc(n);
if ((int)fread(buf, 1, n, f) != n) {
gfree(buf);
fclose(f);
return NULL;
return nullptr;
}
fclose(f);
*fileLen = n;
......
......@@ -34,38 +34,38 @@
//------------------------------------------------------------------------
const char * const fofiType1StandardEncoding[256] = {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"space",
"exclam",
"quotedbl",
......@@ -161,40 +161,40 @@ const char * const fofiType1StandardEncoding[256] = {
"bar",
"braceright",
"asciitilde",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"exclamdown",
"cent",
"sterling",
......@@ -210,12 +210,12 @@ const char * const fofiType1StandardEncoding[256] = {
"guilsinglright",
"fi",
"fl",
NULL,
nullptr,
"endash",
"dagger",
"daggerdbl",
"periodcentered",
NULL,
nullptr,
"paragraph",
"bullet",
"quotesinglbase",
......@@ -224,9 +224,9 @@ const char * const fofiType1StandardEncoding[256] = {
"guillemotright",
"ellipsis",
"perthousand",
NULL,
nullptr,
"questiondown",
NULL,
nullptr,
"grave",
"acute",
"circumflex",
......@@ -235,100 +235,100 @@ const char * const fofiType1StandardEncoding[256] = {
"breve",
"dotaccent",
"dieresis",
NULL,
nullptr,
"ring",
"cedilla",
NULL,
nullptr,
"hungarumlaut",
"ogonek",
"caron",
"emdash",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"AE",
NULL,
nullptr,
"ordfeminine",
NULL,
NULL,
NULL,
NULL,
nullptr,
nullptr,
nullptr,
nullptr,
"Lslash",
"Oslash",
"OE",
"ordmasculine",
NULL,
NULL,
NULL,
NULL,
NULL,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"ae",
NULL,
NULL,
NULL,
nullptr,
nullptr,
nullptr,
"dotlessi",
NULL,
NULL,
nullptr,
nullptr,
"lslash",
"oslash",
"oe",
"germandbls",
NULL,