From 9cca39ec2a8f1b1239369ea16583b9deed162059 Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Sat, 22 Dec 2018 15:29:26 +0100 Subject: [PATCH 1/8] Cleanup --- src/gui/sidebar/previews/layer/SidebarPreviewLayerEntry.h | 4 ++-- src/gui/sidebar/previews/layer/SidebarPreviewLayers.cpp | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/gui/sidebar/previews/layer/SidebarPreviewLayerEntry.h b/src/gui/sidebar/previews/layer/SidebarPreviewLayerEntry.h index 4a148338..bf939eea 100644 --- a/src/gui/sidebar/previews/layer/SidebarPreviewLayerEntry.h +++ b/src/gui/sidebar/previews/layer/SidebarPreviewLayerEntry.h @@ -24,13 +24,13 @@ public: public: /** - * @return What should be renderered + * @return What should be rendered * @override */ virtual PreviewRenderType getRenderType(); /** - * @return The layer to be rendererd + * @return The layer to be rendered */ int getLayer(); diff --git a/src/gui/sidebar/previews/layer/SidebarPreviewLayers.cpp b/src/gui/sidebar/previews/layer/SidebarPreviewLayers.cpp index 4447bc79..d25063d0 100644 --- a/src/gui/sidebar/previews/layer/SidebarPreviewLayers.cpp +++ b/src/gui/sidebar/previews/layer/SidebarPreviewLayers.cpp @@ -8,10 +8,10 @@ #include SidebarPreviewLayers::SidebarPreviewLayers(Control* control, GladeGui* gui, SidebarToolbar* toolbar) - : SidebarPreviewBase(control, gui, toolbar) + : SidebarPreviewBase(control, gui, toolbar), + displayedPage(0) { XOJ_INIT_TYPE(SidebarPreviewLayers); - displayedPage = 0; } SidebarPreviewLayers::~SidebarPreviewLayers() @@ -46,12 +46,10 @@ void SidebarPreviewLayers::updatePreviews() this->previews.clear(); Document* doc = this->getControl()->getDocument(); - // doc->lock(); int len = doc->getPageCount(); if (displayedPage < 0 || displayedPage >= len) { - // doc->unlock(); return; } @@ -72,7 +70,6 @@ void SidebarPreviewLayers::updatePreviews() gtk_layout_put(GTK_LAYOUT(this->iconViewPreview), p->getWidget(), 0, 0); layout(); - // doc->unlock(); } void SidebarPreviewLayers::pageSelected(int page) From 792740e940f8115548e439ea972526fd1d89503b Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Sat, 22 Dec 2018 16:01:28 +0100 Subject: [PATCH 2/8] Windows Build --- src/control/XournalMain.cpp | 5 +++-- src/util/i18n.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/control/XournalMain.cpp b/src/control/XournalMain.cpp index f678fe78..e3a89ebc 100644 --- a/src/control/XournalMain.cpp +++ b/src/control/XournalMain.cpp @@ -46,7 +46,6 @@ XournalMain::~XournalMain() XOJ_RELEASE_TYPE(XournalMain); } -// it HAS to be done – otherwise such things like boost::algorithm::to_lower wont work, throwing casting exceptions void XournalMain::initLocalisation() { XOJ_CHECK_TYPE(XournalMain); @@ -62,7 +61,9 @@ void XournalMain::initLocalisation() textdomain(GETTEXT_PACKAGE); #endif //ENABLE_NLS - std::locale::global(std::locale("")); // "" - system default locale + std::cout << "User-preferred locale setting is " << std::locale("").name().c_str() << '\n'; + +// std::locale::global(std::locale("")); // "" - system default locale std::cout.imbue(std::locale()); } diff --git a/src/util/i18n.h b/src/util/i18n.h index 6505b507..ebce5106 100644 --- a/src/util/i18n.h +++ b/src/util/i18n.h @@ -34,7 +34,7 @@ /* Some helper macros */ -// boost::locale::format → std::string +// PlaceholderString → std::string #define FS(format) (format).str() -// boost::locale::format → char* +// PlaceholderString → const char* #define FC(format) FS(format).c_str() From 4d1a24694630531a31ba70d8d4d0d30aca1ba12f Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Sat, 22 Dec 2018 16:07:05 +0100 Subject: [PATCH 3/8] Windows Build --- src/util/i18n.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/i18n.h b/src/util/i18n.h index ebce5106..d8e12d96 100644 --- a/src/util/i18n.h +++ b/src/util/i18n.h @@ -14,6 +14,7 @@ #include "PlaceholderString.h" #include +#undef snprintf #define _(msg) gettext(msg) #define C_(context, msg) g_dpgettext (NULL, context "\004" msg, strlen(msg) + 1) From 2ff786b4b17620d7fd90c10a62ae38830b24d04c Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Sat, 22 Dec 2018 16:12:48 +0100 Subject: [PATCH 4/8] Use only one numeric formatter, to prevent compiler error --- src/util/PlaceholderString.cpp | 35 +++------------------------------- src/util/PlaceholderString.h | 3 +-- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/src/util/PlaceholderString.cpp b/src/util/PlaceholderString.cpp index 85da54ba..e3d9d8e2 100644 --- a/src/util/PlaceholderString.cpp +++ b/src/util/PlaceholderString.cpp @@ -39,7 +39,7 @@ private: */ class PlaceholderElementInt : public PlaceholderElement{ public: - PlaceholderElementInt(int value) + PlaceholderElementInt(int64_t value) : value(value) { } @@ -51,32 +51,9 @@ public: } private: - int value; + int64_t value; }; - -/** - * Format uint64_t - */ -class PlaceholderElementUint64_t : public PlaceholderElement{ -public: - PlaceholderElementUint64_t(uint64_t value) - : value(value) - { - } - -public: - string format(string format) - { - return std::to_string(value); - } - -private: - uint64_t value; -}; - - - /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// @@ -96,13 +73,7 @@ PlaceholderString::~PlaceholderString() data.clear(); } -PlaceholderString& PlaceholderString::operator%(uint64_t value) -{ - data.push_back(new PlaceholderElementUint64_t(value)); - return *this; -} - -PlaceholderString& PlaceholderString::operator%(int value) +PlaceholderString& PlaceholderString::operator%(int64_t value) { data.push_back(new PlaceholderElementInt(value)); return *this; diff --git a/src/util/PlaceholderString.h b/src/util/PlaceholderString.h index f9ddc70e..9c0d226c 100644 --- a/src/util/PlaceholderString.h +++ b/src/util/PlaceholderString.h @@ -30,8 +30,7 @@ public: // Placeholder methods public: - PlaceholderString& operator%(uint64_t value); - PlaceholderString& operator%(int value); + PlaceholderString& operator%(int64_t value); PlaceholderString& operator%(string value); private: From 350894912704c121ce19086739e82dd565119036 Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Sat, 22 Dec 2018 16:15:06 +0100 Subject: [PATCH 5/8] Windows Build --- src/control/XournalMain.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/control/XournalMain.cpp b/src/control/XournalMain.cpp index e3a89ebc..65cc474a 100644 --- a/src/control/XournalMain.cpp +++ b/src/control/XournalMain.cpp @@ -61,7 +61,8 @@ void XournalMain::initLocalisation() textdomain(GETTEXT_PACKAGE); #endif //ENABLE_NLS - std::cout << "User-preferred locale setting is " << std::locale("").name().c_str() << '\n'; + std::cout << "User-preferred locale setting is "; + std::cout << std::locale("").name().c_str() << '\n'; // std::locale::global(std::locale("")); // "" - system default locale std::cout.imbue(std::locale()); From f8bff6b218864fdf4c048a8088b8ca3db4a2bdd7 Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Sat, 22 Dec 2018 16:28:18 +0100 Subject: [PATCH 6/8] Windows Build --- src/control/XournalMain.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/control/XournalMain.cpp b/src/control/XournalMain.cpp index 65cc474a..bf214e47 100644 --- a/src/control/XournalMain.cpp +++ b/src/control/XournalMain.cpp @@ -23,6 +23,8 @@ #include namespace bf = boost::filesystem; +#include + #if __linux__ #include #endif @@ -61,10 +63,10 @@ void XournalMain::initLocalisation() textdomain(GETTEXT_PACKAGE); #endif //ENABLE_NLS - std::cout << "User-preferred locale setting is "; - std::cout << std::locale("").name().c_str() << '\n'; - -// std::locale::global(std::locale("")); // "" - system default locale + // Not working on Windows! Working on Linux, but not sure if it's needed +#ifndef WIN32 + std::locale::global(std::locale("")); // "" - system default locale +#endif std::cout.imbue(std::locale()); } From 206686863147d014ed78baeacbf13913dac4a8ad Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Sat, 22 Dec 2018 16:29:41 +0100 Subject: [PATCH 7/8] Windows Build --- src/control/XournalMain.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/control/XournalMain.cpp b/src/control/XournalMain.cpp index bf214e47..da72111b 100644 --- a/src/control/XournalMain.cpp +++ b/src/control/XournalMain.cpp @@ -23,8 +23,6 @@ #include namespace bf = boost::filesystem; -#include - #if __linux__ #include #endif From ecbed5c5534dbb19cfe7b925ec3ca8fd8ad72b40 Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Sat, 22 Dec 2018 16:37:37 +0100 Subject: [PATCH 8/8] Catch exception from integer parsing --- src/control/settings/MetadataManager.cpp | 11 ++++++++++- src/util/PlaceholderString.cpp | 13 ++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/control/settings/MetadataManager.cpp b/src/control/settings/MetadataManager.cpp index b16d2c71..f95a1d50 100644 --- a/src/control/settings/MetadataManager.cpp +++ b/src/control/settings/MetadataManager.cpp @@ -172,7 +172,16 @@ MetadataEntry MetadataManager::loadMetadataFile(string path, string file) // Not valid return entry; } - entry.page = std::stoi(line.substr(5)); + + try + { + entry.page = std::stoi(line.substr(5)); + } + catch (const std::exception& e) + { + // Return invalid entry + return entry; + } if (!getline(infile, line)) { diff --git a/src/util/PlaceholderString.cpp b/src/util/PlaceholderString.cpp index e3d9d8e2..a2cfda63 100644 --- a/src/util/PlaceholderString.cpp +++ b/src/util/PlaceholderString.cpp @@ -1,5 +1,7 @@ #include "PlaceholderString.h" +#include + /** * Base class for Formatting */ @@ -96,7 +98,16 @@ string PlaceholderString::formatPart(string format) format = format.substr(0, comma); } - int index = std::stoi(format); + int index; + try + { + index = std::stoi(format); + } + catch (const std::exception& e) + { + g_error("Could not parse «%s» as int, error: %s", format.c_str(), e.what()); + return "{?}"; + } // Placeholder index starting at 1, vector at 0 index--;