From b4bd9c8492b830dcaecc44f979712fe3357de061 Mon Sep 17 00:00:00 2001 From: TheLegendTubaGuy <95944177+thelegendtubaguy@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:55:35 -0600 Subject: [PATCH] Remove null checks before delete (#17375) Deleting a null pointer already does nothing. Enable clang-tidy's readability-delete-null-pointer so new null checks around delete are caught on changed lines, drop the one in DragCanvas's destructor, and remove ParamsPanel::delete_subwindows(), whose only caller is inside #if 0. The --fix help and summary message in the clang-tidy scripts are reworded to "apply clang-tidy's fixes", since this check has its own fix. Closes #7847 --- .clang-tidy | 5 ++- scripts/clang_tidy_diff.py | 4 +- scripts/run_clang_tidy.ps1 | 2 +- scripts/run_clang_tidy.sh | 4 +- src/slic3r/GUI/DragCanvas.cpp | 3 +- src/slic3r/GUI/ParamsPanel.cpp | 82 ---------------------------------- src/slic3r/GUI/ParamsPanel.hpp | 1 - 7 files changed, 9 insertions(+), 92 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 0dea849099..763e92ac46 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ # clang-tidy configuration, enforced by the clang-tidy CI job on the lines a pull -# request changes (scripts/clang_tidy_diff.py). Two things are reported. +# request changes (scripts/clang_tidy_diff.py). Three things are reported. # Missing includes: a file should include the header for every symbol it uses, not # rely on the precompiled header or another header's includes. Run with --fix to # add them. @@ -7,9 +7,10 @@ # they reach every file that includes the header, and a using-declaration also # makes the header look like the one to include for that name. Qualify the name # in the header, and put the using in the source files that want it. +# A null check around delete: deleting a null pointer already does nothing. # Every check listed here gates pull requests, so enable a new one only once the # code it flags on touched lines is reasonable to fix in passing. -Checks: '-*,misc-include-cleaner,google-global-names-in-headers' +Checks: '-*,misc-include-cleaner,google-global-names-in-headers,readability-delete-null-pointer' WarningsAsErrors: '*' CheckOptions: # Missing includes only. Builds without the precompiled header break on these. diff --git a/scripts/clang_tidy_diff.py b/scripts/clang_tidy_diff.py index 1e716b6baf..f9f2761f68 100644 --- a/scripts/clang_tidy_diff.py +++ b/scripts/clang_tidy_diff.py @@ -8,7 +8,7 @@ include) fails wherever the error is. Headers are compiled on their own, and fail only on errors in their changed lines. Deleting an #include also fails on every use, changed or not, that now lacks the header it provided. -With -- --fix, clang-tidy adds the missing includes, on those lines only, and +With -- --fix, clang-tidy applies its fixes, on those lines only, and each file it changed is checked again so that only what remains is reported. The checks come from .clang-tidy at the repository root. The compile database @@ -307,7 +307,7 @@ def main(): print(f"... and {len(diagnostics) - MAX_REPORTED} more") if fixed: - print(f"\nAdded includes to {len(fixed)} file(s):") + print(f"\nApplied clang-tidy's fixes to {len(fixed)} file(s):") for path in fixed: print(f" {path}") if failed and fixed: diff --git a/scripts/run_clang_tidy.ps1 b/scripts/run_clang_tidy.ps1 index 13bd4f4be4..36af0451f4 100644 --- a/scripts/run_clang_tidy.ps1 +++ b/scripts/run_clang_tidy.ps1 @@ -30,7 +30,7 @@ param( [string]$Arch = "", # Parallel clang-tidy runs (default: all cores). [int]$Jobs = 0, - # Apply clang-tidy's fixes (adds the missing includes). + # Apply clang-tidy's fixes. [switch]$Fix, # Install missing tools without asking. [switch]$Yes diff --git a/scripts/run_clang_tidy.sh b/scripts/run_clang_tidy.sh index 70a723f3ac..9f7862ce8c 100755 --- a/scripts/run_clang_tidy.sh +++ b/scripts/run_clang_tidy.sh @@ -3,7 +3,7 @@ # on your branch, so its findings match what CI reports. Linux and macOS. # # scripts/run_clang_tidy.sh check your changes against OrcaSlicer's main -# scripts/run_clang_tidy.sh --fix also add the missing includes it names +# scripts/run_clang_tidy.sh --fix also apply clang-tidy's fixes # # It configures a separate build directory (build-tidy) without the precompiled # header, uses the clang-tidy on your system or installs the pinned one into a @@ -23,7 +23,7 @@ Usage: scripts/run_clang_tidy.sh [options] -d, --deps-dir DIR dependency build directory (default: deps/build on Linux, deps/build/ on macOS) -j, --jobs N parallel clang-tidy runs (default: all cores) - --fix apply clang-tidy's fixes (adds the missing includes) + --fix apply clang-tidy's fixes -y, --yes install missing tools without asking; another clang-tidy version found on the system is then not offered -h, --help show this help diff --git a/src/slic3r/GUI/DragCanvas.cpp b/src/slic3r/GUI/DragCanvas.cpp index a41b1ffde8..78965f86f6 100644 --- a/src/slic3r/GUI/DragCanvas.cpp +++ b/src/slic3r/GUI/DragCanvas.cpp @@ -52,8 +52,7 @@ DragCanvas::~DragCanvas() } m_dragshape_list.clear(); - if (m_drag_image) - delete m_drag_image; + delete m_drag_image; } void DragCanvas::set_shape_list(const std::vector& colors, const std::vector& order) diff --git a/src/slic3r/GUI/ParamsPanel.cpp b/src/slic3r/GUI/ParamsPanel.cpp index e70062eaa8..689fdd8ca8 100644 --- a/src/slic3r/GUI/ParamsPanel.cpp +++ b/src/slic3r/GUI/ParamsPanel.cpp @@ -809,93 +809,11 @@ void ParamsPanel::free_sizers() m_button_sizer = nullptr; } -void ParamsPanel::delete_subwindows() -{ - if (m_title_label) - { - delete m_title_label; - m_title_label = nullptr; - } - - if (m_mode_region) - { - delete m_mode_region; - m_mode_region = nullptr; - } - - if (m_mode_view) - { - m_mode_view = nullptr; - } - - if (m_mode_icon) // ORCA m_title_view replacement - { - delete m_mode_icon; - m_mode_icon = nullptr; - } - - if (m_search_btn) - { - delete m_search_btn; - m_search_btn = nullptr; - } - - if (m_staticline_print) - { - delete m_staticline_print; - m_staticline_print = nullptr; - } - - if (m_staticline_print_part) - { - delete m_staticline_print_part; - m_staticline_print_part = nullptr; - } - - if (m_staticline_print_object) - { - delete m_staticline_print_object; - m_staticline_print_object = nullptr; - } - - if (m_staticline_filament) - { - delete m_staticline_filament; - m_staticline_filament = nullptr; - } - - if (m_staticline_printer) - { - delete m_staticline_printer; - m_staticline_printer = nullptr; - } - - if (m_export_to_file) - { - delete m_export_to_file; - m_export_to_file = nullptr; - } - - if (m_import_from_file) - { - delete m_import_from_file; - m_import_from_file = nullptr; - } - - if (m_page_view) - { - delete m_page_view; - m_page_view = nullptr; - } -} - ParamsPanel::~ParamsPanel() { #if 0 free_sizers(); delete m_top_sizer; - - delete_subwindows(); #endif // BBS: fix double destruct of OG_CustomCtrl Tab* cur_tab = dynamic_cast (m_current_tab); diff --git a/src/slic3r/GUI/ParamsPanel.hpp b/src/slic3r/GUI/ParamsPanel.hpp index 8ae3c34fa3..0d5e156bbc 100644 --- a/src/slic3r/GUI/ParamsPanel.hpp +++ b/src/slic3r/GUI/ParamsPanel.hpp @@ -74,7 +74,6 @@ class ParamsPanel : public wxPanel private: void free_sizers(); - void delete_subwindows(); void refresh_tabs(); protected: