diff --git a/scripts/cpp-check.sh b/scripts/cpp-check.sh index 732cab7d..20de011d 100755 --- a/scripts/cpp-check.sh +++ b/scripts/cpp-check.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash # TODO: add to following flag to the cppcheck: --addon=cert -cppcheck --enable=all --library=googletest --suppressions-list=suppressions.txt --error-exitcode=1 "$@" -I lib/commonmarker/src/ -I lib/commonmarker/extensions/ ./src ./tst +cppcheck --enable=all --library=googletest --suppressions-list=suppressions.txt --inline-suppr --check-level=exhaustive --error-exitcode=1 "$@" -I ./src -I lib/commonmarker/src/ -I lib/commonmarker/extensions/ ./src ./tst diff --git a/src/about-dialog.cc b/src/about-dialog.cc index 697e0f4b..c8c847a6 100644 --- a/src/about-dialog.cc +++ b/src/about-dialog.cc @@ -48,7 +48,7 @@ void About::hide_about(__attribute__((unused)) int response) std::string About::get_logo_image() { // Use data directory first, used when LibreWeb is installed (Linux or Windows) - for (std::string data_dir : Glib::get_system_data_dirs()) + for (const std::string& data_dir : Glib::get_system_data_dirs()) { std::vector path_builder{data_dir, "libreweb", "images", "browser_logo_small.png"}; std::string file_path = Glib::build_path(G_DIR_SEPARATOR_S, path_builder); diff --git a/src/draw.cc b/src/draw.cc index c3f18ab4..e15cfa4a 100644 --- a/src/draw.cc +++ b/src/draw.cc @@ -136,7 +136,7 @@ void Draw::event_after(GdkEvent* ev) if (ev->type == GDK_BUTTON_RELEASE) { - GdkEventButton* event; + const GdkEventButton* event; event = reinterpret_cast(ev); if (event->button != GDK_BUTTON_PRIMARY) return; @@ -145,7 +145,7 @@ void Draw::event_after(GdkEvent* ev) } else if (ev->type == GDK_TOUCH_END) { - GdkEventTouch* event; + const GdkEventTouch* event; event = reinterpret_cast(ev); ex = event->x; ey = event->y; @@ -513,7 +513,7 @@ void Draw::select_all() /** * \brief Return the Texr mark headings for Table of contents */ -std::vector> Draw::get_headings() +const std::vector>& Draw::get_headings() const { return headings_toc_; } @@ -1606,7 +1606,7 @@ void Draw::change_cursor(int x, int y) auto tags = iter.get_tags(); for (auto const& tag : tags) { - char* url = static_cast(tag->get_data("url")); + const char* url = static_cast(tag->get_data("url")); if (url != 0 && (strlen(url) > 0)) { // Link diff --git a/src/draw.h b/src/draw.h index 12ee21cb..a3b56e1a 100644 --- a/src/draw.h +++ b/src/draw.h @@ -53,7 +53,7 @@ class Draw : public Gtk::TextView void paste(); void del(); void select_all(); - std::vector> get_headings(); + const std::vector>& get_headings() const; // Signals editor calls void make_heading(int heading_level); diff --git a/src/ipfs-daemon.cc b/src/ipfs-daemon.cc index 0b517a79..31c29e12 100644 --- a/src/ipfs-daemon.cc +++ b/src/ipfs-daemon.cc @@ -28,6 +28,7 @@ void IPFSDaemon::spawn() // Check for PID under UNIX int daemon_pid = IPFSDaemon::get_existing_pid(); // Is IPFS Daemon already running? + // cppcheck-suppress knownConditionTrueFalse if (daemon_pid > 0) { std::cout << "INFO: IPFS Daemon is already running. Do not start another IPFS process." << std::endl; diff --git a/src/main-window.cc b/src/main-window.cc index be960ff7..93ed46df 100644 --- a/src/main-window.cc +++ b/src/main-window.cc @@ -22,7 +22,7 @@ #include #if defined(__APPLE__) -static void osx_will_quit_cb(__attribute__((unused)) GtkosxApplication* app, __attribute__((unused)) gpointer data) +static void osx_will_quit_cb(__attribute__((unused)) const GtkosxApplication* app, __attribute__((unused)) gpointer data) { gtk_main_quit(); } @@ -358,6 +358,7 @@ void MainWindow::update_status_popover_and_icon() void MainWindow::load_stored_settings() { // Set additional schema directory, when browser is not yet installed + // cppcheck-suppress knownConditionTrueFalse if (!is_installed()) { // Relative to the binary path @@ -1065,6 +1066,7 @@ void MainWindow::init_mac_os() osx_app = reinterpret_cast(g_object_new(GTKOSX_TYPE_APPLICATION, NULL)); // TODO: Should I implement those terminate signals. Since I disabled quartz accelerators MainWindow* mainWindow = this; + // If needed: reinterpret_cast(osx_will_quit_cb)) g_signal_connect(osx_app, "NSApplicationWillTerminate", G_CALLBACK(osx_will_quit_cb), mainWindow); // TODO: Open file callback? // g_signal_connect (osx_app, "NSApplicationOpenFile", G_CALLBACK (osx_open_file_cb), mainWindow); @@ -1266,7 +1268,7 @@ void MainWindow::selectAll() /** * \brief Triggers when the textview widget changes size */ -void MainWindow::on_size_alloc(__attribute__((unused)) Gdk::Rectangle& allocation) +void MainWindow::on_size_alloc(__attribute__((unused)) const Gdk::Rectangle& allocation) { if (!is_editor_enabled()) update_margins(); @@ -1810,7 +1812,7 @@ void MainWindow::forward() /** * \brief Fill-in table of contents and show */ -void MainWindow::set_table_of_contents(std::vector> headings) +void MainWindow::set_table_of_contents(const std::vector>& headings) { Gtk::TreeRow heading1Row, heading2Row, heading3Row, heading4Row, heading5Row; int previousLevel = 1; // Default heading 1 @@ -2083,7 +2085,7 @@ bool MainWindow::is_editor_enabled() std::string MainWindow::get_icon_image_from_theme(const std::string& icon_name, const std::string& typeof_icon) { // Use data directory first, used when LibreWeb is installed (Linux or Windows) - for (std::string data_dir : Glib::get_system_data_dirs()) + for (const std::string& data_dir : Glib::get_system_data_dirs()) { std::vector path_builder{data_dir, "libreweb", "images", "icons", current_icon_theme_, typeof_icon, icon_name + ".png"}; std::string file_path = Glib::build_path(G_DIR_SEPARATOR_S, path_builder); diff --git a/src/main-window.h b/src/main-window.h index ee019f73..b9963c70 100644 --- a/src/main-window.h +++ b/src/main-window.h @@ -75,7 +75,7 @@ class MainWindow : public Gtk::Window void paste(); void del(); void selectAll(); - void on_size_alloc(Gdk::Rectangle& allocation); + void on_size_alloc(const Gdk::Rectangle& allocation); void on_toc_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); void new_doc(); void open(); @@ -334,7 +334,7 @@ class MainWindow : public Gtk::Window void init_signals(); void init_mac_os(); bool is_installed(); - void set_table_of_contents(std::vector> headings); + void set_table_of_contents(const std::vector>& headings); void enable_edit(); void disable_edit(); bool is_editor_enabled(); diff --git a/src/middleware.h b/src/middleware.h index 21d0fec9..ca2c370a 100644 --- a/src/middleware.h +++ b/src/middleware.h @@ -23,7 +23,7 @@ class Middleware : public MiddlewareInterface { public: explicit Middleware(MainWindow& main_window, const std::string& timeout); - virtual ~Middleware(); + virtual ~Middleware() override; void do_request(const std::string& path = std::string(), bool is_set_address_bar = true, bool is_history_request = false, diff --git a/suppressions.txt b/suppressions.txt index f616c778..8beae967 100644 --- a/suppressions.txt +++ b/suppressions.txt @@ -1,4 +1,5 @@ missingIncludeSystem -missingInclude:lib/* +missingInclude unusedFunction *:lib/commonmarker/* +checkersReport