Skip to content

Commit

Permalink
Fix: crashes on client/server
Browse files Browse the repository at this point in the history
  • Loading branch information
NIKEA-SOFT authored and lmoureaux committed May 9, 2022
1 parent 3c5fb16 commit 3c1b68e
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion client/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static enum attribute_serial serialize_hash(attributeHash *hash,
const size_t entries = hash->size();
int total_length;
std::vector<int> value_lengths;
value_lengths.reserve(entries);
value_lengths.resize(entries);
void *result;
struct raw_data_out dout;
int i;
Expand Down
4 changes: 2 additions & 2 deletions client/gui-qt/cityrep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ void city_widget::city_view()
if (gui_options.center_when_popup_city) {
center_tile_mapcanvas(pcity->tile);
}
qtg_real_city_dialog_popup(pcity);
real_city_dialog_popup(pcity);
}

/**
Expand Down Expand Up @@ -1044,7 +1044,7 @@ void city_widget::gen_production_labels(city_widget::menu_labels what,
num_sel = selected_cities.count();
}
std::vector<struct city *> array;
array.reserve(num_sel);
array.resize(num_sel);

if (global) {
i = 0;
Expand Down
16 changes: 8 additions & 8 deletions client/packhand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,12 @@
/* client/include */
#include "citydlg_g.h"
#include "cityrep_g.h"
#include "connectdlg_g.h"
#include "dialogs_g.h"
#include "editgui_g.h"
#include "gui_main_g.h"
#include "inteldlg_g.h"
#include "mapctrl_g.h" // popup_newcity_dialog()
#include "mapview_g.h"
#include "menu_g.h"
#include "messagewin_g.h"
#include "pages_g.h"
#include "plrdlg_g.h"
#include "ratesdlg_g.h"
#include "repodlgs_g.h"
#include "spaceshipdlg_g.h"
Expand All @@ -81,6 +76,7 @@
#include "attribute.h"
#include "audio.h"
#include "chatline_common.h"
#include "citydlg_common.h"
#include "client_main.h"
#include "climap.h"
#include "climisc.h"
Expand All @@ -89,15 +85,20 @@
#include "editor.h"
#include "goto.h" // client_goto_init()
#include "governor.h"
#include "helpdlg_g.h"
#include "mapview_common.h"
#include "messagewin_common.h"
#include "music.h"
#include "options.h"
#include "overview_common.h"
#include "plrdlg_common.h"
#include "tilespec.h"
#include "update_queue.h"
#include "voteinfo.h"

// gui-qt
#include "gui-qt/helpdlg.h"
#include "gui-qt/qtg_cxxside.h"

/* client/luascript */
#include "script_client.h"

Expand Down Expand Up @@ -2364,7 +2365,6 @@ void handle_player_info(const struct packet_player_info *pinfo)

if (pplayer->economic.infra_points != pinfo->infrapoints) {
pplayer->economic.infra_points = pinfo->infrapoints;
update_infra_dialog();
}

/* Don't use player_iterate or player_slot_count here, because we ignore
Expand Down Expand Up @@ -2493,7 +2493,7 @@ void handle_research_info(const struct packet_research_info *packet)
bool tech_changed = false;
bool poptechup = false;
std::vector<Tech_type_id> gained_techs;
gained_techs.reserve(advance_count());
gained_techs.resize(advance_count());
int gained_techs_num = 0, i;
enum tech_state newstate, oldstate;

Expand Down
8 changes: 4 additions & 4 deletions client/reqtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ static struct reqtree *create_dummy_reqtree(struct player *pplayer,
struct reqtree *tree = new reqtree();
int j;
std::vector<struct tree_node *> nodes;
nodes.reserve(advance_count());
nodes.resize(advance_count());

nodes[A_NONE] = nullptr;
advance_index_iterate(A_FIRST, tech)
Expand Down Expand Up @@ -613,7 +613,7 @@ static void set_layers(struct reqtree *tree)
{
// Counters for order - order number for the next node in the layer
std::vector<int> T;
T.reserve(num_layers);
T.resize(num_layers);

tree->layers = new tree_node **[num_layers];
tree->layer_size = new int[num_layers];
Expand Down Expand Up @@ -692,7 +692,7 @@ static int count_crossings(struct reqtree *tree, int layer)
int layer1_size = tree->layer_size[layer];
int layer2_size = tree->layer_size[layer + 1];
std::vector<int> X;
X.reserve(layer2_size);
X.resize(layer2_size);
int i, j, k;
int sum = 0;

Expand Down Expand Up @@ -737,7 +737,7 @@ static void swap(struct reqtree *tree, int layer, int order1, int order2)
static void improve(struct reqtree *tree)
{
std::vector<int> crossings;
crossings.reserve(tree->num_layers - 1);
crossings.resize(tree->num_layers - 1);
int i, x1, x2, layer;

for (i = 0; i < tree->num_layers - 1; i++) {
Expand Down
4 changes: 2 additions & 2 deletions common/aicore/cm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,8 @@ static void top_sort_lattice(struct tile_type_vector *lattice)
int i;
std::vector<bool> marked;
std::vector<bool> will_mark;
marked.reserve(lattice->size);
will_mark.reserve(lattice->size);
marked.resize(lattice->size);
will_mark.resize(lattice->size);

struct tile_type_vector vectors[2];
struct tile_type_vector *current, *next;
Expand Down
3 changes: 2 additions & 1 deletion common/path_finder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ bool path_finder::path_finder_private::run_search(
// Check if we've already found a path (but keep searching if the tip of
// the queue is cheaper: we haven't checked every possibility).
if (auto it = destination.find_best(best_vertices, waypoints.size());
it != best_vertices.end() && !(*it->second > queue.top())) {
it != best_vertices.end()
&& !(!queue.empty() && *it->second > queue.top())) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion common/traderoutes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ static int max_tile_trade(const struct city *pcity, const player *seen_as)
int i, total = 0;
int radius_sq = city_map_radius_sq_get(pcity);
std::vector<int> tile_trade;
tile_trade.reserve(city_map_tiles(radius_sq));
tile_trade.resize(city_map_tiles(radius_sq));
size_t size = 0;
bool is_celebrating = base_city_celebrating(pcity);

Expand Down
4 changes: 2 additions & 2 deletions utility/distribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ void distribute(int number, int groups, int *ratios, int *result)
{
int i, sum = 0, max_count, max;
std::vector<int> rest, max_groups;
rest.reserve(groups);
max_groups.reserve(groups);
rest.resize(groups);
max_groups.resize(groups);
#ifdef FREECIV_DEBUG
const int original_number = number;
#endif
Expand Down

0 comments on commit 3c1b68e

Please sign in to comment.