From 7ea1a69feb36d4580e581077dd3f939451d1c854 Mon Sep 17 00:00:00 2001 From: MarPiRK Date: Wed, 25 Nov 2015 21:39:32 +0100 Subject: [PATCH] Coverity Scan based fixes Fixes some issues from Coverity report, fixed Travis Coverity support. --- .travis.yml | 12 +- src/control/ToolHandler.cpp | 110 +++++++++--------- src/gui/TextEditor.cpp | 6 +- src/gui/toolbarMenubar/model/ToolbarModel.cpp | 29 ++--- src/gui/toolbarMenubar/model/ToolbarModel.h | 4 +- src/model/LinkDestination.cpp | 1 + src/pdf/popplerdirect/PdfExport.cpp | 2 +- 7 files changed, 77 insertions(+), 87 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6c8f2300..9b2c64b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,20 +5,19 @@ language: # clang is not supported for poppler compiler: gcc +cache: +- ccache + os: linux sudo: false -cache: -- ccache - env: - global: + global: # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created # via the "travis encrypt" command using the project repo's public key - secure: "DxwzqXcJV/9qPwUCi7DQrqzeU73ACRhS0i8suV9tYpUDJ7ZuwwSK/GMVt2jMTNjZbJwKFv8ELLu0MIdTfX3UvG+++lfxLx4yldEwl4CtjPJaClB2rTou2SAiZPMBMyX6eHKfx0XB4xtsqwtKRIvF47tB9i3w+aPcb8C4DE6hXmU=" - addons: apt: packages: @@ -46,7 +45,7 @@ addons: name: "MarPiRK/xournalpp" description: "Notetaking software designed around a tablet." notification_email: marek@pikula.co - build_command_prepend: "mkdir build && cd build && cmake .. -DBUILD_POPPLER=ON -DEXT_GLIBMM=ON -DENABLE_MATHTEX=ON -DENABLE_OS=ON -DENABLE_CPPUNIT=ON -DUNSTABLE_LAYERS_SIDEBAR=ON" + build_command_prepend: "cmake .. -DBUILD_POPPLER=ON -DEXT_GLIBMM=ON -DENABLE_MATHTEX=ON -DENABLE_OS=ON -DENABLE_CPPUNIT=ON -DUNSTABLE_LAYERS_SIDEBAR=ON" build_command: "make" branch_pattern: coverity_scan @@ -60,7 +59,6 @@ script: - "ctest" notifications: - slack: xournalpp:D5mvotdm0Rnn0ejvZf0FIxgV webhooks: urls: - https://webhooks.gitter.im/e/4879506130dac18d2f63 diff --git a/src/control/ToolHandler.cpp b/src/control/ToolHandler.cpp index bc3df906..b4c005c1 100644 --- a/src/control/ToolHandler.cpp +++ b/src/control/ToolHandler.cpp @@ -568,74 +568,74 @@ void ToolHandler::loadSettings() SElement& s = settings->getCustomElement("tools"); string selectedTool; - s.getString("current", selectedTool); - - ArrayIterator it = iterator(); - - for (; it.hasNext();) + if (s.getString("current", selectedTool)) { - Tool* t = it.next(); - SElement& st = s.child(t->getName()); + ArrayIterator it = iterator(); - if (selectedTool == t->getName()) + for (; it.hasNext();) { - this->current = t; - } + Tool* t = it.next(); + SElement& st = s.child(t->getName()); - int color = 0; - if (t->isEnableColor() && st.getInt("color", color)) - { - t->setColor(color); - } + if (selectedTool == t->getName()) + { + this->current = t; + } - bool enabled = false; - if (t->isEnableRuler() && st.getBool("ruler", enabled)) - { - t->setRuler(enabled); - } - if (t->isEnableRectangle() && st.getBool("rectangle", enabled)) - { - t->setRectangle(enabled); - } - if (t->isEnableCircle() && st.getBool("circle", enabled)) - { - t->setCircle(enabled); - } - if (t->isEnableArrow() && st.getBool("arrow", enabled)) - { - t->setArrow(enabled); - } - if (t->isEnableShapeRecognizer() && st.getBool("shapeRecognizer", enabled)) - { - t->setShapeRecognizer(enabled); - } + int color = 0; + if (t->isEnableColor() && st.getInt("color", color)) + { + t->setColor(color); + } - string value; + bool enabled = false; + if (t->isEnableRuler() && st.getBool("ruler", enabled)) + { + t->setRuler(enabled); + } + if (t->isEnableRectangle() && st.getBool("rectangle", enabled)) + { + t->setRectangle(enabled); + } + if (t->isEnableCircle() && st.getBool("circle", enabled)) + { + t->setCircle(enabled); + } + if (t->isEnableArrow() && st.getBool("arrow", enabled)) + { + t->setArrow(enabled); + } + if (t->isEnableShapeRecognizer() && st.getBool("shapeRecognizer", enabled)) + { + t->setShapeRecognizer(enabled); + } - if (t->isEnableSize() && st.getString("size", value)) - { - if (value == "VERY_THIN") t->setSize(TOOL_SIZE_VERY_FINE); - else if (value == "THIN") t->setSize(TOOL_SIZE_FINE); - else if (value == "MEDIUM") t->setSize(TOOL_SIZE_MEDIUM); - else if (value == "BIG") t->setSize(TOOL_SIZE_THICK); - else if (value == "VERY_BIG") t->setSize(TOOL_SIZE_VERY_THICK); - else g_warning("Settings::Unknown tool size: %s\n", value.c_str()); - } + string value; - if (t->type == TOOL_ERASER) - { - string type; + if (t->isEnableSize() && st.getString("size", value)) + { + if (value == "VERY_THIN") t->setSize(TOOL_SIZE_VERY_FINE); + else if (value == "THIN") t->setSize(TOOL_SIZE_FINE); + else if (value == "MEDIUM") t->setSize(TOOL_SIZE_MEDIUM); + else if (value == "BIG") t->setSize(TOOL_SIZE_THICK); + else if (value == "VERY_BIG") t->setSize(TOOL_SIZE_VERY_THICK); + else g_warning("Settings::Unknown tool size: %s\n", value.c_str()); + } - if (st.getString("type", type)) + if (t->type == TOOL_ERASER) { - if (type == "deleteStroke") setEraserType(ERASER_TYPE_DELETE_STROKE); - else if (type == "whiteout") setEraserType(ERASER_TYPE_WHITEOUT); - else setEraserType(ERASER_TYPE_DEFAULT); - eraserTypeChanged(); + string type; + + if (st.getString("type", type)) + { + if (type == "deleteStroke") setEraserType(ERASER_TYPE_DELETE_STROKE); + else if (type == "whiteout") setEraserType(ERASER_TYPE_WHITEOUT); + else setEraserType(ERASER_TYPE_DEFAULT); + eraserTypeChanged(); + } } } } - } void ToolHandler::copyCurrentConfig() diff --git a/src/gui/TextEditor.cpp b/src/gui/TextEditor.cpp index 1b8f751d..423fa47b 100644 --- a/src/gui/TextEditor.cpp +++ b/src/gui/TextEditor.cpp @@ -733,7 +733,7 @@ void TextEditor::deleteFromCursor(GtkDeleteType type, int count) XOJ_CHECK_TYPE(TextEditor); GtkTextIter insert; - bool leave_one = false; + //gboolean leave_one = false; // not needed this->resetImContext(); @@ -854,10 +854,10 @@ void TextEditor::deleteFromCursor(GtkDeleteType type, int count) if (gtk_text_buffer_delete_interactive(this->buffer, &start, &end, true)) { - if (leave_one) + /*if (leave_one) // leave_one is statically false { gtk_text_buffer_insert_interactive_at_cursor(this->buffer, " ", 1, true); - } + }*/ } else { diff --git a/src/gui/toolbarMenubar/model/ToolbarModel.cpp b/src/gui/toolbarMenubar/model/ToolbarModel.cpp index f8c9e104..423d695b 100644 --- a/src/gui/toolbarMenubar/model/ToolbarModel.cpp +++ b/src/gui/toolbarMenubar/model/ToolbarModel.cpp @@ -2,7 +2,7 @@ #include "ToolbarData.h" -#include +#include ToolbarModel::ToolbarModel() { @@ -35,17 +35,7 @@ void ToolbarModel::parseGroup(GKeyFile* config, const char* group, bool predefin ToolbarData* data = new ToolbarData(predefined); - string name; - if (predefined) - { - name = "predef_"; - } - else - { - name = "custom_"; - } - - data->name = name; + data->name = (predefined ? "predef_" : "custom_"); data->id = group; data->load(config, group); @@ -57,7 +47,7 @@ void ToolbarModel::remove(ToolbarData* data) { XOJ_CHECK_TYPE(ToolbarModel); - for (unsigned int i = 0; i < this->toolbars.size(); i++) + for (size_t i = 0; i < this->toolbars.size(); i++) { if (this->toolbars[i] == data) { @@ -74,13 +64,13 @@ void ToolbarModel::add(ToolbarData* data) this->toolbars.push_back(data); } -bool ToolbarModel::parse(const char* file, bool predefined) +bool ToolbarModel::parse(string filename, bool predefined) { XOJ_CHECK_TYPE(ToolbarModel); GKeyFile* config = g_key_file_new(); g_key_file_set_list_separator(config, ','); - if (!g_key_file_load_from_file(config, file, G_KEY_FILE_NONE, NULL)) + if (!g_key_file_load_from_file(config, filename.c_str(), G_KEY_FILE_NONE, NULL)) { g_key_file_free(config); return false; @@ -139,7 +129,7 @@ const char* TOOLBAR_INI_HEADER = " LAYER: The layer dropdown menu\n" "\n"; -void ToolbarModel::save(const char* filename) +void ToolbarModel::save(string filename) { GKeyFile* config = g_key_file_new(); g_key_file_set_list_separator(config, ','); @@ -157,8 +147,9 @@ void ToolbarModel::save(const char* filename) gsize len = 0; char* data = g_key_file_to_data(config, &len, NULL); - FILE* fp = fopen(filename, "w"); - fwrite(data, 1, len, fp); - fclose(fp); + std::ofstream f(filename); + f.write(data, len); + f.close(); + g_free(data); } diff --git a/src/gui/toolbarMenubar/model/ToolbarModel.h b/src/gui/toolbarMenubar/model/ToolbarModel.h index b0d3fe40..09c4a94e 100644 --- a/src/gui/toolbarMenubar/model/ToolbarModel.h +++ b/src/gui/toolbarMenubar/model/ToolbarModel.h @@ -25,10 +25,10 @@ public: public: ToolbarDataVector* getToolbars(); - bool parse(const char* file, bool predefined); + bool parse(string filename, bool predefined); void add(ToolbarData* data); void remove(ToolbarData* data); - void save(const char* filename); + void save(string filename); bool existsId(string id); private: diff --git a/src/model/LinkDestination.cpp b/src/model/LinkDestination.cpp index 37c24550..992832f2 100644 --- a/src/model/LinkDestination.cpp +++ b/src/model/LinkDestination.cpp @@ -57,6 +57,7 @@ LinkDestination::LinkDestination() this->zoom = 0; this->left = 0; this->top = 0; + this->expand = false; } LinkDestination::~LinkDestination() diff --git a/src/pdf/popplerdirect/PdfExport.cpp b/src/pdf/popplerdirect/PdfExport.cpp index 5fab7d9a..ff1392f4 100644 --- a/src/pdf/popplerdirect/PdfExport.cpp +++ b/src/pdf/popplerdirect/PdfExport.cpp @@ -306,7 +306,7 @@ void PdfExport::writeGzStream(Stream* str, GList* replacementList) string text = GzHelper::gzuncompress(string(buffer, length)); writeStream(text.c_str(), text.length(), replacementList); - delete buffer; + delete[] buffer; str->reset(); }