From d4d380cc9f5ae30fc0251343380ac205e752baa4 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Sun, 5 May 2024 15:06:27 +0500 Subject: [PATCH] fixed pvs-studio warnings --- src/RBTree.hpp | 6 ++---- src/UsefulException.cpp | 2 +- src/UsefulException.hpp | 2 +- src/format.cpp | 2 +- src/format.hpp | 2 +- src/gui/GraphEditor.cpp | 16 ++++++++++------ src/gui/GraphEditor.hpp | 4 ++-- src/gui/exceptions.cpp | 2 +- src/gui/exceptions.hpp | 4 ++-- src/gui/gui.cpp | 10 +++++----- src/gui/gui.hpp | 6 +++--- src/main.cpp | 2 +- 12 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/RBTree.hpp b/src/RBTree.hpp index f46c2e1..dbff5ea 100644 --- a/src/RBTree.hpp +++ b/src/RBTree.hpp @@ -26,10 +26,8 @@ class RBTree { } ~Node(){ - if(left != nullptr) - delete left; - if(right != nullptr) - delete right; + delete left; + delete right; } inline Node* getSibling(){ diff --git a/src/UsefulException.cpp b/src/UsefulException.cpp index ac39ff9..48e6b02 100644 --- a/src/UsefulException.cpp +++ b/src/UsefulException.cpp @@ -1,7 +1,7 @@ #include "UsefulException.hpp" #include -UsefulException_::UsefulException_(std::string _message, std::string _file, std::string _func, int _line_n) +UsefulException_::UsefulException_(const std::string& _message, const std::string& _file, const std::string& _func, int _line_n) : message(_message), file(_file), function(_func), line_n(_line_n) { std::stringstream ss; diff --git a/src/UsefulException.hpp b/src/UsefulException.hpp index de53447..39955d6 100644 --- a/src/UsefulException.hpp +++ b/src/UsefulException.hpp @@ -13,7 +13,7 @@ class UsefulException_ : public std::exception { std::string complete_text; public: - UsefulException_(std::string msg, std::string _file, std::string _func, int line_n); + UsefulException_(const std::string& msg, const std::string& _file, const std::string& _func, int line_n); virtual char const* what() const noexcept; }; diff --git a/src/format.cpp b/src/format.cpp index 15c05fc..da4a469 100644 --- a/src/format.cpp +++ b/src/format.cpp @@ -4,7 +4,7 @@ #include "UsefulException.hpp" #include "../dependencies/kerep/src/base/base.h" -std::string _format(const std::string format_str, size_t args_count, ...){ +std::string _format(const std::string& format_str, const size_t args_count, ...){ va_list vl; va_start(vl, args_count); std::stringstream ss; diff --git a/src/format.hpp b/src/format.hpp index acb41f6..bf7b4b6 100644 --- a/src/format.hpp +++ b/src/format.hpp @@ -3,5 +3,5 @@ #include #include "../dependencies/kerep/src/base/std.h" -std::string _format(const std::string format_str, size_t args_count, ...); +std::string _format(const std::string& format_str, const size_t args_count, ...); #define format(FORMAT_STR, ARGS...) _format(FORMAT_STR, count_args(ARGS) ,##ARGS) diff --git a/src/gui/GraphEditor.cpp b/src/gui/GraphEditor.cpp index 8183253..abe8a97 100644 --- a/src/gui/GraphEditor.cpp +++ b/src/gui/GraphEditor.cpp @@ -35,7 +35,7 @@ void GraphEditor::drawNode(const GraphModel::Node& node){ } } - const char* items[]={ + static const char* items[]={ "static","input", "output" }; static int selected_item_i = 0; @@ -81,15 +81,15 @@ void GraphEditor::drawNode(const GraphModel::Node& node){ } -GraphModel::Node* GraphEditor::CreateExampleNode(std::string title){ - GraphModel::Node* n = graph.createNode(GraphModel::Node(graph.id_gen.getNext(), title)); +GraphModel::Node* GraphEditor::CreateExampleNode(const std::string& node_title){ + GraphModel::Node* n = graph.createNode(GraphModel::Node(graph.id_gen.getNext(), node_title)); graph.createAttribute(GraphModel::Attribute(graph.id_gen.getNext(), n, GraphModel::Attribute::Type::Input, "In")); graph.createAttribute(GraphModel::Attribute(graph.id_gen.getNext(), n, GraphModel::Attribute::Type::Output, "Out")); graph.createAttribute(GraphModel::Attribute(graph.id_gen.getNext(), n, GraphModel::Attribute::Type::Static, "Static")); return n; } -GraphEditor::GraphEditor(std::string _title) +GraphEditor::GraphEditor(const std::string& _title) : title(_title) { // CreateExampleNode("Node A"); @@ -153,8 +153,10 @@ void GraphEditor::draw(){ GraphModel::id_t from_attr_id, to_attr_id; if (ImNodes::IsLinkCreated(&from_attr_id, &to_attr_id)) { - if(!graph.tryCreateEdge(from_attr_id, to_attr_id, nullptr)) + if(!graph.tryCreateEdge(from_attr_id, to_attr_id, nullptr)){ + ImGui::End(); throw UsefulException(format("can't create edge from attribute %i to attribute %i", from_attr_id, to_attr_id)); + } std::cout<<"EDGES:\n"; std::cout<draw(); // Rendering @@ -235,10 +235,10 @@ void GUI::draw_bg_window(){ ImGui::End(); } -void GUI::draw_debug_window(ImGuiIO& io, bool* main_loop_wait_for_input){ +void GUI::draw_debug_window(ImGuiIO& io){ ImGui::Begin("Debug Options"); ImGui::ColorEdit3("clear_color", (float*)&clear_color); - ImGui::Checkbox("main_loop_wait_for_input", main_loop_wait_for_input); + ImGui::Checkbox("main_loop_wait_for_input", &main_loop_wait_for_input); ImGui::Text("Application average %.3f ms/frame (%.2f FPS)", 1000.0f / io.Framerate, io.Framerate); ImGui::Checkbox("Demo Window", &show_demo_window); ImGui::Checkbox("Metrics/Debug Window", &show_metrics_window); diff --git a/src/gui/gui.hpp b/src/gui/gui.hpp index 37968d6..b317828 100644 --- a/src/gui/gui.hpp +++ b/src/gui/gui.hpp @@ -34,8 +34,8 @@ private: bool main_loop_wait_for_input=true; bool show_demo_window = false; bool show_metrics_window = false; - SDL_Window* sdl_window; - SDL_GLContext gl_context; + SDL_Window* sdl_window = nullptr; + SDL_GLContext gl_context = nullptr; GraphEditor* node_editor = nullptr; public: @@ -48,7 +48,7 @@ private: void destroy(); void poll_events(u16& frame_updates_requested, bool wait); void draw_frame(); - void draw_debug_window(ImGuiIO &io, bool *main_loop_wait_for_input); + void draw_debug_window(ImGuiIO &io); void draw_bg_window(); }; diff --git a/src/main.cpp b/src/main.cpp index 962606c..8274c38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,7 +27,7 @@ int main(const int argc, const char* const* argv){ std::cerr<<"Catched exception message: "<