mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-08 21:54:19 +00:00
Change sprintf calls to snprintf in trunk.
This commit is contained in:
parent
86231387d8
commit
e4beea352c
@ -789,7 +789,7 @@ void attack(display& gui, const gamemap& map,
|
||||
if(dies || hits) {
|
||||
if(stats.amount_attacker_drains > 0) {
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",stats.amount_attacker_drains);
|
||||
snprintf(buf,sizeof(buf),"%d",stats.amount_attacker_drains);
|
||||
gui.float_label(a->first,buf,0,255,0);
|
||||
a->second.heal(stats.amount_attacker_drains);
|
||||
}
|
||||
@ -959,7 +959,7 @@ void attack(display& gui, const gamemap& map,
|
||||
if(hits || dies){
|
||||
if(stats.amount_defender_drains > 0) {
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",stats.amount_defender_drains);
|
||||
snprintf(buf,sizeof(buf),"%d",stats.amount_defender_drains);
|
||||
gui.float_label(d->first,buf,0,255,0);
|
||||
d->second.heal(stats.amount_defender_drains);
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ void cave_map_generator::place_items(const chamber& c, config::all_children_iter
|
||||
std::advance(loc,index);
|
||||
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",loc->x+1);
|
||||
snprintf(buf,sizeof(buf),"%d",loc->x+1);
|
||||
cfg.values["x"] = buf;
|
||||
if(filter != NULL) {
|
||||
(*filter)["x"] = buf;
|
||||
@ -256,7 +256,7 @@ void cave_map_generator::place_items(const chamber& c, config::all_children_iter
|
||||
(*object_filter)["x"] = buf;
|
||||
}
|
||||
|
||||
sprintf(buf,"%d",loc->y+1);
|
||||
snprintf(buf,sizeof(buf),"%d",loc->y+1);
|
||||
cfg.values["y"] = buf;
|
||||
if(filter != NULL) {
|
||||
(*filter)["y"] = buf;
|
||||
|
@ -1261,9 +1261,9 @@ void display::draw_unit_on_tile(int x, int y, surface unit_image_override,
|
||||
if(preferences::show_side_colours()) {
|
||||
const char* const selected = selectedHex_ == loc ? "selected-" : "";
|
||||
char buf[50];
|
||||
sprintf(buf,"misc/%sellipse-%d-top.png",selected,team::get_side_colour_index(it->second.side()));
|
||||
snprintf(buf,sizeof(buf),"misc/%sellipse-%d-top.png",selected,team::get_side_colour_index(it->second.side()));
|
||||
ellipse_back.assign(image::get_image(buf));
|
||||
sprintf(buf,"misc/%sellipse-%d-bottom.png",selected,team::get_side_colour_index(it->second.side()));
|
||||
snprintf(buf,sizeof(buf),"misc/%sellipse-%d-bottom.png",selected,team::get_side_colour_index(it->second.side()));
|
||||
ellipse_front.assign(image::get_image(buf));
|
||||
}
|
||||
|
||||
|
@ -549,7 +549,7 @@ bool game_controller::play_multiplayer_mode()
|
||||
}
|
||||
|
||||
char buf[20];
|
||||
sprintf(buf,"%d",side_num);
|
||||
snprintf(buf,sizeof(buf),"%d",side_num);
|
||||
(*itors.first)->values["side"] = buf;
|
||||
|
||||
(*itors.first)->values["canrecruit"] = "1";
|
||||
|
@ -487,7 +487,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
||||
const size_t team_index = side_num-1;
|
||||
if(team_index < teams->size()) {
|
||||
char value[50];
|
||||
sprintf(value,"%d",(*teams)[team_index].gold());
|
||||
snprintf(value,sizeof(value),"%d",(*teams)[team_index].gold());
|
||||
wassert(state_of_game != NULL);
|
||||
state_of_game->set_variable(var_name,value);
|
||||
}
|
||||
@ -676,7 +676,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
||||
int value = int(atof(var.c_str()));
|
||||
value += atoi(add.c_str());
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",value);
|
||||
snprintf(buf,sizeof(buf),"%d",value);
|
||||
var = buf;
|
||||
}
|
||||
|
||||
@ -685,7 +685,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
||||
int value = int(atof(var.c_str()));
|
||||
value = int(double(value) * atof(multiply.c_str()));
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",value);
|
||||
snprintf(buf,sizeof(buf),"%d",value);
|
||||
var = buf;
|
||||
}
|
||||
|
||||
@ -1727,16 +1727,16 @@ bool pump()
|
||||
//set the variables for the event
|
||||
if(i.first != i.second && state_of_game != NULL) {
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",ev.loc1.x+1);
|
||||
snprintf(buf,sizeof(buf),"%d",ev.loc1.x+1);
|
||||
state_of_game->variables["x1"] = buf;
|
||||
|
||||
sprintf(buf,"%d",ev.loc1.y+1);
|
||||
snprintf(buf,sizeof(buf),"%d",ev.loc1.y+1);
|
||||
state_of_game->variables["y1"] = buf;
|
||||
|
||||
sprintf(buf,"%d",ev.loc2.x+1);
|
||||
snprintf(buf,sizeof(buf),"%d",ev.loc2.x+1);
|
||||
state_of_game->variables["x2"] = buf;
|
||||
|
||||
sprintf(buf,"%d",ev.loc2.y+1);
|
||||
snprintf(buf,sizeof(buf),"%d",ev.loc2.y+1);
|
||||
state_of_game->variables["y2"] = buf;
|
||||
}
|
||||
|
||||
|
@ -60,16 +60,16 @@ time_of_day::time_of_day(const config& cfg)
|
||||
void time_of_day::write(config& cfg) const
|
||||
{
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",lawful_bonus);
|
||||
snprintf(buf,sizeof(buf),"%d",lawful_bonus);
|
||||
cfg["lawful_bonus"] = buf;
|
||||
|
||||
sprintf(buf,"%d",red);
|
||||
snprintf(buf,sizeof(buf),"%d",red);
|
||||
cfg["red"] = buf;
|
||||
|
||||
sprintf(buf,"%d",green);
|
||||
snprintf(buf,sizeof(buf),"%d",green);
|
||||
cfg["green"] = buf;
|
||||
|
||||
sprintf(buf,"%d",blue);
|
||||
snprintf(buf,sizeof(buf),"%d",blue);
|
||||
cfg["blue"] = buf;
|
||||
|
||||
cfg["image"] = image;
|
||||
@ -323,7 +323,7 @@ game_state read_game(const game_data& data, const config* cfg)
|
||||
void write_player(const player_info& player, config& cfg)
|
||||
{
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",player.gold);
|
||||
snprintf(buf,sizeof(buf),"%d",player.gold);
|
||||
|
||||
cfg["gold"] = buf;
|
||||
|
||||
|
@ -126,9 +126,9 @@ gamemap::location::location(const config& cfg) : x(-1), y(-1)
|
||||
void gamemap::location::write(config& cfg) const
|
||||
{
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",x+1);
|
||||
snprintf(buf,sizeof(buf),"%d",x+1);
|
||||
cfg["x"] = buf;
|
||||
sprintf(buf,"%d",y+1);
|
||||
snprintf(buf,sizeof(buf),"%d",y+1);
|
||||
cfg["y"] = buf;
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ void replay::add_recruit(int value, const gamemap::location& loc)
|
||||
config val;
|
||||
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",value);
|
||||
snprintf(buf,sizeof(buf),"%d",value);
|
||||
val["value"] = buf;
|
||||
|
||||
loc.write(val);
|
||||
@ -244,7 +244,7 @@ void replay::add_recall(int value, const gamemap::location& loc)
|
||||
config val;
|
||||
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",value);
|
||||
snprintf(buf,sizeof(buf),"%d",value);
|
||||
val["value"] = buf;
|
||||
|
||||
loc.write(val);
|
||||
@ -259,7 +259,7 @@ void replay::add_disband(int value)
|
||||
config val;
|
||||
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",value);
|
||||
snprintf(buf,sizeof(buf),"%d",value);
|
||||
val["value"] = buf;
|
||||
|
||||
cmd->add_child("disband",val);
|
||||
@ -274,7 +274,7 @@ void replay::add_attack(const gamemap::location& a, const gamemap::location& b,
|
||||
{
|
||||
add_pos("attack",a,b);
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",weapon);
|
||||
snprintf(buf,sizeof(buf),"%d",weapon);
|
||||
current_->child("attack")->values["weapon"] = buf;
|
||||
}
|
||||
|
||||
@ -299,7 +299,7 @@ void replay::add_value(const std::string& type, int value)
|
||||
config val;
|
||||
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",value);
|
||||
snprintf(buf,sizeof(buf),"%d",value);
|
||||
val["value"] = buf;
|
||||
|
||||
cmd->add_child(type,val);
|
||||
|
@ -391,7 +391,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
||||
|
||||
case SIDE_PLAYING: {
|
||||
char buf[50];
|
||||
sprintf(buf,"terrain/flag-team%d-1.png",team::get_side_colour_index(playing_side));
|
||||
snprintf(buf,sizeof(buf),"terrain/flag-team%d-1.png",team::get_side_colour_index(playing_side));
|
||||
|
||||
u = find_leader(units,playing_side);
|
||||
return report("",buf,u != units.end() ? u->second.description() : "");
|
||||
|
@ -95,7 +95,7 @@ namespace {
|
||||
std::string describe_turns(int turn, const std::string& num_turns)
|
||||
{
|
||||
char buf[50];
|
||||
sprintf(buf,"%d/",int(turn));
|
||||
snprintf(buf,sizeof(buf),"%d/",int(turn));
|
||||
|
||||
if(num_turns == "-1") {
|
||||
return buf + std::string("-");
|
||||
@ -341,7 +341,7 @@ bool game::describe_slots()
|
||||
|
||||
const int val = int(available_slots());
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",val);
|
||||
snprintf(buf,sizeof(buf),"%d",val);
|
||||
|
||||
if(buf != (*description())["slots"]) {
|
||||
description()->values["slots"] = buf;
|
||||
|
@ -84,7 +84,7 @@ config write_str_int_map(const stats::str_int_map& m)
|
||||
config res;
|
||||
for(stats::str_int_map::const_iterator i = m.begin(); i != m.end(); ++i) {
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",i->second);
|
||||
snprintf(buf,sizeof(buf),"%d",i->second);
|
||||
res[i->first] = buf;
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ config write_battle_result_map(const stats::battle_result_map& m)
|
||||
new_cfg = write_str_int_map(i->second);
|
||||
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",i->first);
|
||||
snprintf(buf,sizeof(buf),"%d",i->first);
|
||||
new_cfg["_num"] = buf;
|
||||
}
|
||||
|
||||
@ -188,22 +188,22 @@ config stats::write() const
|
||||
res.add_child("defends",write_battle_result_map(defends));
|
||||
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",recruit_cost);
|
||||
snprintf(buf,sizeof(buf),"%d",recruit_cost);
|
||||
res["recruit_cost"] = buf;
|
||||
|
||||
sprintf(buf,"%d",recall_cost);
|
||||
snprintf(buf,sizeof(buf),"%d",recall_cost);
|
||||
res["recall_cost"] = buf;
|
||||
|
||||
sprintf(buf,"%d",damage_inflicted);
|
||||
snprintf(buf,sizeof(buf),"%d",damage_inflicted);
|
||||
res["damage_inflicted"] = buf;
|
||||
|
||||
sprintf(buf,"%d",damage_taken);
|
||||
snprintf(buf,sizeof(buf),"%d",damage_taken);
|
||||
res["damage_taken"] = buf;
|
||||
|
||||
sprintf(buf,"%d",expected_damage_inflicted);
|
||||
snprintf(buf,sizeof(buf),"%d",expected_damage_inflicted);
|
||||
res["expected_damage_inflicted"] = buf;
|
||||
|
||||
sprintf(buf,"%d",expected_damage_taken);
|
||||
snprintf(buf,sizeof(buf),"%d",expected_damage_taken);
|
||||
res["expected_damage_taken"] = buf;
|
||||
|
||||
return res;
|
||||
|
12
src/team.cpp
12
src/team.cpp
@ -234,7 +234,7 @@ void team::team_info::write(config& cfg) const
|
||||
cfg["objectives_changed"] = objectives_changed ? "yes" : "no";
|
||||
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",income_per_village);
|
||||
snprintf(buf,sizeof(buf),"%d",income_per_village);
|
||||
cfg["village_gold"] = buf;
|
||||
|
||||
std::stringstream enemies_str;
|
||||
@ -255,13 +255,13 @@ void team::team_info::write(config& cfg) const
|
||||
}
|
||||
cfg["persistent"] = persistent ? "1" : "0";
|
||||
|
||||
sprintf(buf,"%d",villages_per_scout);
|
||||
snprintf(buf,sizeof(buf),"%d",villages_per_scout);
|
||||
cfg["villages_per_scout"] = buf;
|
||||
|
||||
sprintf(buf,"%f",leader_value);
|
||||
snprintf(buf,sizeof(buf),"%f",leader_value);
|
||||
cfg["leader_value"] = buf;
|
||||
|
||||
sprintf(buf,"%f",village_value);
|
||||
snprintf(buf,sizeof(buf),"%f",village_value);
|
||||
cfg["village_value"] = buf;
|
||||
|
||||
for(std::vector<target>::const_iterator tg = targets.begin(); tg != targets.end(); ++tg) {
|
||||
@ -324,7 +324,7 @@ void team::write(config& cfg) const
|
||||
cfg["fog"] = uses_fog() ? "yes" : "no";
|
||||
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",gold_);
|
||||
snprintf(buf,sizeof(buf),"%d",gold_);
|
||||
cfg["gold"] = buf;
|
||||
|
||||
//write village locations
|
||||
@ -904,4 +904,4 @@ void team::log_recruitable(){
|
||||
LOG_NG << *it << std::endl;
|
||||
}
|
||||
LOG_NG << "Added all recruitable units\n";
|
||||
}
|
||||
}
|
||||
|
@ -830,12 +830,12 @@ void unit::write(config& cfg) const
|
||||
}
|
||||
|
||||
char buf[50];
|
||||
sprintf(buf,"%d",goto_.x+1);
|
||||
snprintf(buf,sizeof(buf),"%d",goto_.x+1);
|
||||
cfg["goto_x"] = buf;
|
||||
sprintf(buf,"%d",goto_.y+1);
|
||||
snprintf(buf,sizeof(buf),"%d",goto_.y+1);
|
||||
cfg["goto_y"] = buf;
|
||||
|
||||
sprintf(buf,"%d",moves_);
|
||||
snprintf(buf,sizeof(buf),"%d",moves_);
|
||||
cfg["moves"] = buf;
|
||||
|
||||
cfg["resting"] = resting_ ? "yes" : "no";
|
||||
|
Loading…
x
Reference in New Issue
Block a user