>From a language lawyer PoV, size_t is not %lu.

But we would not have to care, if it wasn't wrong with some ABIs
too. So let's be cautious and use C++ idioms here.
This commit is contained in:
Guillaume Melquiond 2005-01-28 20:17:46 +00:00
parent 2a7493df15
commit 9ee046f8df
4 changed files with 23 additions and 23 deletions

View file

@ -1576,13 +1576,14 @@ config config::get_diff(const config& c) const
} else {
//we have to work out what the most appropriate operation --
//delete, insert, or change is the best to get b[bi] looking like a[ai]
std::stringstream buf;
//if b has more elements than a, then we assume this element is an
//element that needs deleting
if(b.size() - bi > a.size() - ai) {
config& new_delete = res.add_child("delete_child");
char buf[50];
sprintf(buf,"%lu",bi-ndeletes);
new_delete.values["index"] = buf;
buf << bi - ndeletes;
new_delete.values["index"] = buf.str();
new_delete.add_child(*itor);
++ndeletes;
@ -1593,9 +1594,8 @@ config config::get_diff(const config& c) const
//element that needs inserting
else if(b.size() - bi < a.size() - ai) {
config& new_insert = res.add_child("insert_child");
char buf[50];
sprintf(buf,"%lu",ai);
new_insert.values["index"] = buf;
buf << ai;
new_insert.values["index"] = buf.str();
new_insert.add_child(*itor,*a[ai]);
++ai;
@ -1605,9 +1605,8 @@ config config::get_diff(const config& c) const
//changing this element to match
else {
config& new_change = res.add_child("change_child");
char buf[50];
sprintf(buf,"%lu",bi);
new_change.values["index"] = buf;
buf << bi;
new_change.values["index"] = buf.str();
new_change.add_child(*itor,a[ai]->get_diff(*b[bi]));
++ai;

View file

@ -102,12 +102,12 @@ gamestatus::gamestatus(config& time_cfg, int num_turns) :
void gamestatus::write(config& cfg) const
{
char buf[50];
sprintf(buf,"%lu",turn_);
cfg["turn_at"] = buf;
sprintf(buf,"%d",numTurns_);
cfg["turns"] = buf;
std::stringstream buf;
buf << turn_;
cfg["turn_at"] = buf.str();
buf.str(std::string());
buf << numTurns_;
cfg["turns"] = buf.str();
std::vector<time_of_day>::const_iterator t;
for(t = times_.begin(); t != times_.end(); ++t) {

View file

@ -1607,9 +1607,9 @@ void turn_info::write_game_snapshot(config& start) const
start["snapshot"] = "yes";
char buf[50];
sprintf(buf,"%lu",gui_.playing_team());
start["playing_team"] = buf;
std::stringstream buf;
buf << gui_.playing_team();
start["playing_team"] = buf.str();
for(std::vector<team>::const_iterator t = teams_.begin(); t != teams_.end(); ++t) {
const int side_num = t - teams_.begin() + 1;
@ -1617,8 +1617,9 @@ void turn_info::write_game_snapshot(config& start) const
config& side = start.add_child("side");
t->write(side);
side["no_leader"] = "yes";
sprintf(buf,"%d",side_num);
side["side"] = buf;
buf.str(std::string());
buf << side_num;
side["side"] = buf.str();
for(std::map<gamemap::location,unit>::const_iterator i = units_.begin(); i != units_.end(); ++i) {
if(i->second.side() == side_num) {

View file

@ -105,9 +105,9 @@ namespace {
config create_verification(const unit_map& units)
{
config res;
char buf[50];
sprintf(buf,"%lu",units.size());
res["num_units"] = buf;
std::stringstream buf;
buf << units.size();
res["num_units"] = buf.str();
for(unit_map::const_iterator i = units.begin(); i != units.end(); ++i) {
config u;