diff --git a/Source/documents/Misc. info.txt b/Source/documents/Misc. info.txt index f5dd273cd..c21c09773 100644 --- a/Source/documents/Misc. info.txt +++ b/Source/documents/Misc. info.txt @@ -519,6 +519,8 @@ Procedure for every version release valgrind --leak-check=yes ./pikifen 2> valgrind.txt Use clang analyze and correct problems make CXX=clang++ -f Source/gnu_make/makefile analyze + Use Infer and correct problems + infer run -o ~/Desktop/infer-out --report-block-list-files-containing "libs/imgui" -- make -f Source/gnu_make/makefile debug Confirm that there are no superfluous #includes (how?) Code cleanup Confirm that no line goes over 80 characters diff --git a/Source/source/animation.cpp b/Source/source/animation.cpp index 0057507fd..e75dde18b 100644 --- a/Source/source/animation.cpp +++ b/Source/source/animation.cpp @@ -246,7 +246,8 @@ void animation_database::calculate_hitbox_span() { * report errors. */ void animation_database::create_conversions( - vector > conversions, const data_node* file + const vector >& conversions, + const data_node* file ) { pre_named_conversions.clear(); @@ -496,7 +497,7 @@ void animation_database::load_from_data_node(data_node* node) { vector hazards_strs = semicolon_list_to_vector(cur_hitbox.hazards_str); for(size_t hs = 0; hs < hazards_strs.size(); hs++) { - string hazard_name = hazards_strs[hs]; + const string& hazard_name = hazards_strs[hs]; if(game.content.hazards.find(hazard_name) == game.content.hazards.end()) { game.errors.report( "Unknown hazard \"" + hazard_name + "\"!", diff --git a/Source/source/animation.h b/Source/source/animation.h index 98ba5d9e1..a02aadfed 100644 --- a/Source/source/animation.h +++ b/Source/source/animation.h @@ -274,7 +274,8 @@ class animation_database : public content { size_t find_body_part(const string &name) const; void calculate_hitbox_span(); void create_conversions( - vector > conversions, const data_node* file + const vector >& conversions, + const data_node* file ); void delete_sprite(size_t idx); void fill_sound_idx_caches(mob_type* mt_ptr); diff --git a/Source/source/area/geometry.cpp b/Source/source/area/geometry.cpp index 1821ded76..9f8f809dd 100644 --- a/Source/source/area/geometry.cpp +++ b/Source/source/area/geometry.cpp @@ -754,7 +754,7 @@ TRIANGULATION_ERROR get_polys( * @return Whether it is an outer polygon. */ bool get_polys_is_outer( - vertex* v_ptr, const sector* s_ptr, unordered_set edges_left, + vertex* v_ptr, const sector* s_ptr, const unordered_set& edges_left, bool doing_first_polygon ) { if(doing_first_polygon) { diff --git a/Source/source/area/geometry.h b/Source/source/area/geometry.h index ed511c938..977151dfe 100644 --- a/Source/source/area/geometry.h +++ b/Source/source/area/geometry.h @@ -158,7 +158,7 @@ TRIANGULATION_ERROR get_polys( sector* s_ptr, vector* outers, vector>* inners ); bool get_polys_is_outer( - vertex* v_ptr, const sector* s_ptr, unordered_set edges_left, + vertex* v_ptr, const sector* s_ptr, const unordered_set& edges_left, bool doing_first_polygon ); vertex* get_rightmost_vertex(const unordered_set &edges); diff --git a/Source/source/edge_offset.cpp b/Source/source/edge_offset.cpp index 30df90ac8..ce417c671 100644 --- a/Source/source/edge_offset.cpp +++ b/Source/source/edge_offset.cpp @@ -756,7 +756,7 @@ void update_offset_effect_buffer( */ void update_offset_effect_caches ( vector &caches, - unordered_set vertexes_to_update, + const unordered_set& vertexes_to_update, offset_effect_checker_t checker, offset_effect_length_getter_t length_getter, offset_effect_color_getter_t color_getter diff --git a/Source/source/functions.cpp b/Source/source/functions.cpp index 1b7f7900c..2cafc5000 100644 --- a/Source/source/functions.cpp +++ b/Source/source/functions.cpp @@ -54,7 +54,7 @@ bool are_walls_between( float ignore_walls_below_z, bool* out_impassable_walls ) { point bb_tl(std::min(p1.x, p2.x), std::min(p1.y, p2.y)); - point bb_br(std::max(p1.x, p1.x), std::max(p2.y, p2.y)); + point bb_br(std::max(p1.x, p2.x), std::max(p1.y, p2.y)); set candidate_edges; if( @@ -694,11 +694,7 @@ vector > get_weather_table(data_node* node) { for(size_t p = 0; p < n_points; p++) { data_node* point_node = node->get_child(p); - - int point_time = s2i(point_node->name); - string point_value = point_node->value; - - table.push_back(make_pair(point_time, point_value)); + table.push_back(make_pair(s2i(point_node->name), point_node->value)); } sort( diff --git a/Source/source/functions.h b/Source/source/functions.h index 3c3d6f57a..fcec27348 100644 --- a/Source/source/functions.h +++ b/Source/source/functions.h @@ -173,7 +173,7 @@ void update_offset_effect_buffer( ); void update_offset_effect_caches ( vector &caches, - unordered_set vertexes_to_update, + const unordered_set& vertexes_to_update, offset_effect_checker_t checker, offset_effect_length_getter_t length_getter, offset_effect_color_getter_t color_getter diff --git a/Source/source/game_states/animation_editor/editor.cpp b/Source/source/game_states/animation_editor/editor.cpp index dc543c9e7..c417d5954 100644 --- a/Source/source/game_states/animation_editor/editor.cpp +++ b/Source/source/game_states/animation_editor/editor.cpp @@ -834,7 +834,7 @@ void animation_editor::zoom_everything_cmd(float input_value) { sprite* s_ptr = cur_sprite; if(!s_ptr && cur_anim_i.valid_frame()) { - string name = + const string& name = cur_anim_i.cur_anim->frames[cur_anim_i.cur_frame_idx].sprite_name; size_t s_pos = anims.find_sprite(name); if(s_pos != INVALID) s_ptr = anims.sprites[s_pos]; @@ -920,7 +920,7 @@ void animation_editor::rename_animation( return; } - string old_name = anim->name; + const string& old_name = anim->name; //Check if the name is the same. if(new_name == old_name) { @@ -969,7 +969,7 @@ void animation_editor::rename_body_part( return; } - string old_name = part->name; + const string& old_name = part->name; //Check if the name is the same. if(new_name == old_name) { @@ -1026,7 +1026,7 @@ void animation_editor::rename_sprite( return; } - string old_name = spr->name; + const string& old_name = spr->name; //Check if the name is the same. if(new_name == old_name) { @@ -1500,7 +1500,7 @@ void animation_editor::update_hitboxes() { //Add missing hitboxes. for(size_t b = 0; b < anims.body_parts.size(); b++) { bool hitbox_found = false; - string name = anims.body_parts[b]->name; + const string& name = anims.body_parts[b]->name; for(size_t h = 0; h < s_ptr->hitboxes.size(); h++) { if(s_ptr->hitboxes[h].body_part_name == name) { diff --git a/Source/source/game_states/area_editor/editor.cpp b/Source/source/game_states/area_editor/editor.cpp index c0679a00f..9f45bf524 100644 --- a/Source/source/game_states/area_editor/editor.cpp +++ b/Source/source/game_states/area_editor/editor.cpp @@ -570,22 +570,17 @@ void area_editor::create_mob_under_cursor() { sub_state = EDITOR_SUB_STATE_NONE; point hotspot = snap_point(game.mouse_cursor.w_pos); - string custom_cat_name_to_use = last_mob_custom_cat_name; - mob_type* type_to_use = last_mob_type; - if(custom_cat_name_to_use.empty()) { - custom_cat_name_to_use = + if(last_mob_custom_cat_name.empty()) { + last_mob_custom_cat_name = game.config.pikmin_order[0]->custom_category_name; - type_to_use = + last_mob_type = game.config.pikmin_order[0]; } game.cur_area_data.mob_generators.push_back( - new mob_gen(hotspot, type_to_use) + new mob_gen(hotspot, last_mob_type) ); - last_mob_custom_cat_name = custom_cat_name_to_use; - last_mob_type = type_to_use; - selected_mobs.insert(game.cur_area_data.mob_generators.back()); set_status("Created object."); @@ -1921,12 +1916,10 @@ void area_editor::load_area( const AREA_TYPE requested_area_type, bool from_backup, bool should_update_history ) { - string new_area_name = requested_area_folder_name; - clear_current_area(); ::load_area( - new_area_name, requested_area_type, true, from_backup + requested_area_folder_name, requested_area_type, true, from_backup ); //Calculate texture suggestions. @@ -1934,7 +1927,7 @@ void area_editor::load_area( vector > texture_uses_vector; for(size_t s = 0; s < game.cur_area_data.sectors.size(); s++) { - string n = game.cur_area_data.sectors[s]->texture_info.file_name; + const string& n = game.cur_area_data.sectors[s]->texture_info.file_name; if(n.empty()) continue; texture_uses_map[n]++; } @@ -1973,13 +1966,13 @@ void area_editor::load_area( if(should_update_history) { update_history( get_base_area_folder_path(requested_area_type, true) + "/" + - new_area_name + requested_area_folder_name ); save_options(); //Save the history in the options. } set_status( - "Loaded area \"" + new_area_name + "\" " + + "Loaded area \"" + requested_area_folder_name + "\" " + (from_backup ? "from a backup " : "") + "successfully." ); diff --git a/Source/source/game_states/area_editor/geometry_logic.cpp b/Source/source/game_states/area_editor/geometry_logic.cpp index 8012d290c..8a116e807 100644 --- a/Source/source/game_states/area_editor/geometry_logic.cpp +++ b/Source/source/game_states/area_editor/geometry_logic.cpp @@ -1903,11 +1903,10 @@ bool area_editor::merge_sectors(sector* s1, sector* s2) { void area_editor::merge_vertex( const vertex* v1, vertex* v2, unordered_set* affected_sectors ) { - vector edges = v1->edges; //Find out what to do with every edge of the dragged vertex. - for(size_t e = 0; e < edges.size(); e++) { + for(size_t e = 0; e < v1->edges.size(); e++) { - edge* e_ptr = edges[e]; + edge* e_ptr = v1->edges[e]; vertex* other_vertex = e_ptr->get_other_vertex(v1); if(other_vertex == v2) { diff --git a/Source/source/game_states/area_menu.cpp b/Source/source/game_states/area_menu.cpp index 2d1dd1818..fb81bb358 100644 --- a/Source/source/game_states/area_menu.cpp +++ b/Source/source/game_states/area_menu.cpp @@ -936,7 +936,7 @@ void area_menu_state::load() { "/" + actual_name + "/" + AREA_DATA_FILE_NAME ); if(data.file_was_opened) { - string s = data.get_child_by_name("name")->value; + const string& s = data.get_child_by_name("name")->value; if(!s.empty()) { actual_name = s; } diff --git a/Source/source/game_states/editor.cpp b/Source/source/game_states/editor.cpp index 8061ad35f..cc3131eaf 100644 --- a/Source/source/game_states/editor.cpp +++ b/Source/source/game_states/editor.cpp @@ -1534,9 +1534,9 @@ void editor::process_gui_unsaved_changes_dialog() { ImGui::SameLine(0.0f, 10); if(ImGui::Button("Save", ImVec2(180, 30))) { close_top_dialog(); - const std::function save_callback = + const std::function& save_callback = changes_mgr.get_unsaved_warning_save_callback(); - const std::function action_callback = + const std::function& action_callback = changes_mgr.get_unsaved_warning_action_callback(); if(save_callback()) { action_callback(); @@ -2029,9 +2029,9 @@ bool editor::changes_manager::ask_if_unsaved( ed->key_check(ev->keyboard.keycode, ALLEGRO_KEY_S, true) ) { ed->close_top_dialog(); - const std::function save_callback = + const std::function& save_callback = this->get_unsaved_warning_save_callback(); - const std::function action_callback = + const std::function& action_callback = this->get_unsaved_warning_action_callback(); if(save_callback()) { action_callback(); @@ -2040,7 +2040,7 @@ bool editor::changes_manager::ask_if_unsaved( ed->key_check(ev->keyboard.keycode, ALLEGRO_KEY_D, true) ) { ed->close_top_dialog(); - const std::function action_callback = + const std::function& action_callback = this->get_unsaved_warning_action_callback(); action_callback(); } diff --git a/Source/source/game_states/gameplay/drawing.cpp b/Source/source/game_states/gameplay/drawing.cpp index fc133b69a..7230d6966 100644 --- a/Source/source/game_states/gameplay/drawing.cpp +++ b/Source/source/game_states/gameplay/drawing.cpp @@ -330,7 +330,7 @@ void gameplay_state::draw_big_msg() { } case BIG_MESSAGE_MISSION_CLEAR: case BIG_MESSAGE_MISSION_FAILED: { - const string TEXT = + const string& TEXT = cur_big_msg == BIG_MESSAGE_MISSION_CLEAR ? GAMEPLAY::BIG_MSG_MISSION_CLEAR_TEXT : GAMEPLAY::BIG_MSG_MISSION_FAILED_TEXT; @@ -1752,9 +1752,9 @@ ALLEGRO_BITMAP* gameplay_state::draw_to_bitmap() { //Figure out the scale that will fit on the image. float area_w = max_x - min_x + game.maker_tools.area_image_padding; float area_h = max_y - min_y + game.maker_tools.area_image_padding; - float scale = 1.0f; float final_bmp_w = game.maker_tools.area_image_size; float final_bmp_h = final_bmp_w; + float scale; if(area_w > area_h) { scale = game.maker_tools.area_image_size / area_w; diff --git a/Source/source/init.cpp b/Source/source/init.cpp index 6643f5ef2..e4a13f235 100644 --- a/Source/source/init.cpp +++ b/Source/source/init.cpp @@ -520,7 +520,7 @@ void init_controls() { const vector &action_types = game.controls.get_all_player_action_types(); for(size_t a = 0; a < action_types.size(); a++) { - string def = action_types[a].default_bind_str; + const string& def = action_types[a].default_bind_str; if(def.empty()) continue; control_bind bind; diff --git a/Source/source/libs/data_file.cpp b/Source/source/libs/data_file.cpp index 794b7c946..75bc2031e 100644 --- a/Source/source/libs/data_file.cpp +++ b/Source/source/libs/data_file.cpp @@ -532,7 +532,7 @@ bool data_node::remove(data_node* node_to_remove) { * @brief Saves a node into a new text file. Line numbers are ignored. * If you don't provide a file name, it'll use the node's file name. * - * @param file_path Path to the file to save to. + * @param destination_file_path Path to the file to save to. * @param children_only If true, only save the nodes inside this node. * @param include_empty_values If true, even nodes with an empty value * will be saved. @@ -540,24 +540,24 @@ bool data_node::remove(data_node* node_to_remove) { * @return Whether it succeded. */ bool data_node::save_file( - string file_path, bool children_only, + string destination_file_path, bool children_only, bool include_empty_values, bool encrypted ) const { - if(file_path == "") file_path = this->file_path; + if(destination_file_path == "") destination_file_path = this->file_path; //Create any missing folders. - size_t next_slash_pos = file_path.find('/', 0); + size_t next_slash_pos = destination_file_path.find('/', 0); while(next_slash_pos != string::npos) { - string path_so_far = file_path.substr(0, next_slash_pos); + string path_so_far = destination_file_path.substr(0, next_slash_pos); if(!al_make_directory(path_so_far.c_str())) { return false; } - next_slash_pos = file_path.find('/', next_slash_pos + 1); + next_slash_pos = destination_file_path.find('/', next_slash_pos + 1); } //Save the file. - ALLEGRO_FILE* file = al_fopen(file_path.c_str(), "w"); + ALLEGRO_FILE* file = al_fopen(destination_file_path.c_str(), "w"); if(file) { if(children_only) { for(size_t c = 0; c < children.size(); c++) { diff --git a/Source/source/libs/data_file.h b/Source/source/libs/data_file.h index add70897c..d0d9edaec 100644 --- a/Source/source/libs/data_file.h +++ b/Source/source/libs/data_file.h @@ -112,7 +112,7 @@ class data_node { bool names_only_after_root = false ); bool save_file( - string file_path = "", bool children_only = true, + string destination_file_path = "", bool children_only = true, bool include_empty_values = false, bool encrypted = false ) const; diff --git a/Source/source/mob_script.cpp b/Source/source/mob_script.cpp index f846bc982..dba623b90 100644 --- a/Source/source/mob_script.cpp +++ b/Source/source/mob_script.cpp @@ -142,7 +142,7 @@ mob_event::mob_event( #define r(name, number) \ else if(n == (name)) type = (number) - string n = node->name; + const string& n = node->name; if(n == "on_enter") type = MOB_EV_ON_ENTER; r("on_leave", MOB_EV_ON_LEAVE); r("on_tick", MOB_EV_ON_TICK); diff --git a/Source/source/mob_script_action.cpp b/Source/source/mob_script_action.cpp index 0cca72d46..65e651a08 100644 --- a/Source/source/mob_script_action.cpp +++ b/Source/source/mob_script_action.cpp @@ -2370,22 +2370,19 @@ bool assert_actions( set labels; for(size_t a = 0; a < actions.size(); a++) { if(actions[a]->action->type == MOB_ACTION_LABEL) { - - string name = actions[a]->args[0]; - + const string& name = actions[a]->args[0]; if(labels.find(name) != labels.end()) { game.errors.report( "There are multiple labels called \"" + name + "\"!", dn ); return false; } - labels.insert(name); } } for(size_t a = 0; a < actions.size(); a++) { if(actions[a]->action->type == MOB_ACTION_GOTO) { - string name = actions[a]->args[0]; + const string& name = actions[a]->args[0]; if(labels.find(name) == labels.end()) { game.errors.report( "There is no label called \"" + name + "\", even though " diff --git a/Source/source/mobs/mob.cpp b/Source/source/mobs/mob.cpp index b9b27369e..b60d7feb6 100644 --- a/Source/source/mobs/mob.cpp +++ b/Source/source/mobs/mob.cpp @@ -2311,7 +2311,7 @@ void mob::get_sprite_bitmap_effects( ) { float damage_squash_time_ratio = damage_squash_time / MOB::DAMAGE_SQUASH_DURATION; - float damage_scale_y = 1.0f; + float damage_scale_y; if(damage_squash_time_ratio > 0.5) { damage_scale_y = interpolate_number( diff --git a/Source/source/utils/drawing_utils.cpp b/Source/source/utils/drawing_utils.cpp index 5b4e5486c..9c84d48b7 100644 --- a/Source/source/utils/drawing_utils.cpp +++ b/Source/source/utils/drawing_utils.cpp @@ -544,9 +544,10 @@ void get_multiline_text_dimensions( int* out_width, int* out_height, int* out_line_height ) { int lh = al_get_font_line_height(font); - size_t n_lines = lines.size(); - if(out_height) *out_height = std::max(0, (int) ((lh + 1) * n_lines) - 1); + if(out_height) { + *out_height = std::max(0, (int) ((lh + 1) * lines.size()) - 1); + } if(out_width) { int largest_w = 0; diff --git a/Source/source/utils/geometry_utils.cpp b/Source/source/utils/geometry_utils.cpp index d85c13b56..da66306e2 100644 --- a/Source/source/utils/geometry_utils.cpp +++ b/Source/source/utils/geometry_utils.cpp @@ -552,7 +552,8 @@ void calculate_throw( //If the target is above the maximum height it can be thrown... //Then this is an impossible throw. *req_speed_xy = point(); - *req_speed_z = 0; + *req_speed_z = 0.0f; + if(out_h_angle) *out_h_angle = 0.0f; return; }