fixed pvs-studio warnings

This commit is contained in:
Timerix22 2024-05-05 15:06:27 +05:00
parent f9bd8c1184
commit d4d380cc9f
12 changed files with 30 additions and 28 deletions

View File

@ -26,10 +26,8 @@ class RBTree {
}
~Node(){
if(left != nullptr)
delete left;
if(right != nullptr)
delete right;
delete left;
delete right;
}
inline Node* getSibling(){

View File

@ -1,7 +1,7 @@
#include "UsefulException.hpp"
#include <sstream>
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;

View File

@ -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;
};

View File

@ -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;

View File

@ -3,5 +3,5 @@
#include <string>
#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)

View File

@ -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<<graph.getEdges().generateGraphVizCode()<<std::endl;
}
@ -163,8 +165,10 @@ void GraphEditor::draw(){
GraphModel::id_t edge_id;
if (ImNodes::IsLinkDestroyed(&edge_id))
{
if(!graph.tryDeleteEdge(edge_id))
if(!graph.tryDeleteEdge(edge_id)){
ImGui::End();
throw UsefulException(format("can't delete edge with id %i", edge_id));
}
std::cout<<"EDGES:\n";
std::cout<<graph.getEdges().generateGraphVizCode()<<std::endl;
}

View File

@ -13,10 +13,10 @@ class GraphEditor {
GraphModel::Graph graph;
void drawNode(const GraphModel::Node& node);
GraphModel::Node* CreateExampleNode(std::string title);
GraphModel::Node* CreateExampleNode(const std::string& title);
public:
GraphEditor(std::string _title);
GraphEditor(const std::string& _title);
void draw();
void show();

View File

@ -3,7 +3,7 @@
namespace GraphC::gui {
SDLException_::SDLException_(std::string _file, std::string _func, int _line_n)
SDLException_::SDLException_(const std::string& _file,const std::string& _func, int _line_n)
: UsefulException_(SDL_GetError(), _file, _func, _line_n)
{
SDL_ClearError();

View File

@ -6,9 +6,9 @@ namespace GraphC::gui {
#define SDLException() SDLException_(__FILE__, __func__, __LINE__)
class SDLException_ : UsefulException_ {
class SDLException_ : public UsefulException_ {
public:
SDLException_(std::string _file, std::string _func, int line_n);
SDLException_(const std::string& _file, const std::string& _func, int line_n);
};
#define SDL_TRY_ZERO(FUNC_CALL) if(FUNC_CALL != 0) throw SDLException();

View File

@ -9,8 +9,8 @@ f32 GUI::getDPI(){
SDL_GL_GetDrawableSize(sdl_window, &w, &h);
int sim_w=0, sim_h=0;
SDL_GetWindowSize(sdl_window, &sim_w, &sim_h);
f32 wdpi=w/sim_w;
f32 hdpi=h/sim_h;
f32 wdpi=(f32)w / sim_w;
f32 hdpi=(f32)h / sim_h;
f32 dpi=SDL_sqrtf(wdpi*wdpi + hdpi*hdpi);
return dpi;
}
@ -117,7 +117,7 @@ void GUI::draw_frame(){
// Draw UI
draw_bg_window();
draw_debug_window(io, &main_loop_wait_for_input);
draw_debug_window(io);
node_editor->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);

View File

@ -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();
};

View File

@ -27,7 +27,7 @@ int main(const int argc, const char* const* argv){
std::cerr<<"Catched exception message: "<<msg<<std::endl;
return -1;
}
catch(std::string& msg){
catch(const std::string& msg){
std::cerr<<"Catched exception message: "<<msg<<std::endl;
return -1;
}