summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2009-12-17 12:48:02 +0100
committerAdam Borowski <kilobyte@angband.pl>2009-12-17 12:48:02 +0100
commit1ab177757bec9eb28482785f75fd8a4fb8a1313c (patch)
tree4b1c8babcca442dc8b91a624b842bc5f30013747
parentc266f14414471d5252130c70bafa0c60f85a265c (diff)
downloadcrawl-ref-1ab177757bec9eb28482785f75fd8a4fb8a1313c.tar.gz
crawl-ref-1ab177757bec9eb28482785f75fd8a4fb8a1313c.zip
Replace static snprintf() with make_sprintf() where the result is immediately cast
to std::string.
-rw-r--r--crawl-ref/source/clua.cc4
-rw-r--r--crawl-ref/source/files.cc4
-rw-r--r--crawl-ref/source/format.cc5
-rw-r--r--crawl-ref/source/hiscores.cc10
-rw-r--r--crawl-ref/source/items.cc15
-rw-r--r--crawl-ref/source/message.cc1
-rw-r--r--crawl-ref/source/mon-act.cc7
-rw-r--r--crawl-ref/source/ouch.cc3
-rw-r--r--crawl-ref/source/place.cc11
-rw-r--r--crawl-ref/source/shopping.cc15
-rw-r--r--crawl-ref/source/stash.cc15
-rw-r--r--crawl-ref/source/stuff.cc4
-rw-r--r--crawl-ref/source/tags.cc9
-rw-r--r--crawl-ref/source/wiz-fsim.cc4
14 files changed, 32 insertions, 75 deletions
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc
index b30e84dc1e..2cd15a4bbf 100644
--- a/crawl-ref/source/clua.cc
+++ b/crawl-ref/source/clua.cc
@@ -839,9 +839,7 @@ void lua_text_pattern::post_pattern(std::string &pat, std::string &fn) const
std::string lua_text_pattern::new_fn_name()
{
- char buf[100];
- snprintf(buf, sizeof buf, "__ch_stash_search_%lu", lfndx++);
- return (buf);
+ return (make_stringf("__ch_stash_search_%lu", lfndx++));
}
bool lua_text_pattern::translate() const
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc
index b05bbde518..45a0664a5b 100644
--- a/crawl-ref/source/files.cc
+++ b/crawl-ref/source/files.cc
@@ -136,9 +136,7 @@ static void _redraw_all(void)
static std::string _uid_as_string()
{
#ifdef MULTIUSER
- char struid[20];
- snprintf( struid, sizeof struid, "-%d", static_cast<int>(getuid()) );
- return std::string(struid);
+ return make_stringf("-%d", static_cast<int>(getuid()));
#else
return std::string();
#endif
diff --git a/crawl-ref/source/format.cc b/crawl-ref/source/format.cc
index a65613adff..59fc8152bf 100644
--- a/crawl-ref/source/format.cc
+++ b/crawl-ref/source/format.cc
@@ -514,13 +514,10 @@ void formatted_string::clear()
void formatted_string::cprintf(const char *s, ...)
{
- char buf[1000];
va_list args;
va_start(args, s);
- vsnprintf(buf, sizeof buf, s, args);
+ cprintf(make_stringf(s, args));
va_end(args);
-
- cprintf(std::string(buf));
}
void formatted_string::cprintf(const std::string &s)
diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc
index 81bf6479e8..cbbd3b518c 100644
--- a/crawl-ref/source/hiscores.cc
+++ b/crawl-ref/source/hiscores.cc
@@ -1430,10 +1430,9 @@ std::string scorefile_entry::death_place(death_desc_verbosity verbosity) const
if (verbosity == DDV_ONELINE || verbosity == DDV_TERSE)
{
- snprintf( scratch, sizeof scratch, " (%s)",
- place_name(get_packed_place(branch, dlvl, level_type),
- false, true).c_str());
- return (scratch);
+ return (make_stringf(" (%s)",
+ place_name(get_packed_place(branch, dlvl, level_type),
+ false, true).c_str()));
}
if (verbose && death_type != KILLED_BY_QUITTING)
@@ -2122,10 +2121,9 @@ void xlog_fields::add_field(const std::string &key,
const char *format,
...)
{
- char buf[500];
va_list args;
va_start(args, format);
- vsnprintf(buf, sizeof buf, format, args);
+ std::string buf = make_stringf(format, args);
va_end(args);
fields.push_back( std::pair<std::string, std::string>( key, buf ) );
diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc
index a167165398..a3418761d4 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -2010,7 +2010,6 @@ bool drop_item( int item_dropped, int quant_drop, bool try_offer )
static std::string _drop_menu_invstatus(const Menu *menu)
{
- char buf[100];
const int cap = carrying_capacity(BS_UNENCUMBERED);
std::string s_newweight;
@@ -2024,15 +2023,13 @@ static std::string _drop_menu_invstatus(const Menu *menu)
newweight -= item_mass(*item) * se[i]->selected_qty;
}
- snprintf(buf, sizeof buf, ">%.0f", newweight * BURDEN_TO_AUM);
- s_newweight = buf;
+ s_newweight = make_stringf(">%.0f", newweight * BURDEN_TO_AUM);
}
- snprintf(buf, sizeof buf, "(Inv: %.0f%s/%.0f aum)",
+ return (make_stringf("(Inv: %.0f%s/%.0f aum)",
you.burden * BURDEN_TO_AUM,
s_newweight.c_str(),
- cap * BURDEN_TO_AUM);
- return (buf);
+ cap * BURDEN_TO_AUM));
}
static std::string _drop_menu_title(const Menu *menu, const std::string &oldt)
@@ -2081,7 +2078,6 @@ mon_inv_type get_mon_equip_slot(const monsters* mon, const item_def &item)
static std::string _drop_selitem_text( const std::vector<MenuEntry*> *s )
{
- char buf[130];
bool extraturns = false;
if (s->empty())
@@ -2098,11 +2094,10 @@ static std::string _drop_selitem_text( const std::vector<MenuEntry*> *s )
}
}
- snprintf( buf, sizeof buf, " (%lu%s turn%s)",
+ return (make_stringf( " (%lu%s turn%s)",
(unsigned long) (s->size()),
extraturns? "+" : "",
- s->size() > 1? "s" : "" );
- return buf;
+ s->size() > 1? "s" : "" ));
}
std::vector<SelItem> items_for_multidrop;
diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc
index d0fc3e7e9f..c2fce04242 100644
--- a/crawl-ref/source/message.cc
+++ b/crawl-ref/source/message.cc
@@ -413,6 +413,7 @@ int channel_to_colour( msg_channel_type channel, int param )
static void do_message_print( msg_channel_type channel, int param,
const char *format, va_list argp )
{
+ // Is this limit intentional?
char buff[200];
vsnprintf( buff, sizeof( buff ), format, argp );
buff[199] = 0;
diff --git a/crawl-ref/source/mon-act.cc b/crawl-ref/source/mon-act.cc
index 4e866cec38..16c025e217 100644
--- a/crawl-ref/source/mon-act.cc
+++ b/crawl-ref/source/mon-act.cc
@@ -1324,22 +1324,19 @@ static bool _mons_throw(struct monsters *monster, struct bolt &pbolt,
// [dshaligram] When changing bolt names here, you must edit
// hiscores.cc (scorefile_entry::terse_missile_cause()) to match.
- char throw_buff[ITEMNAME_SIZE];
if (projected == LRET_LAUNCHED)
{
- snprintf(throw_buff, sizeof(throw_buff), "Shot with a%s %s by %s",
+ pbolt.aux_source = make_stringf("Shot with a%s %s by %s",
(is_vowel(pbolt.name[0]) ? "n" : ""), pbolt.name.c_str(),
monster->name(DESC_NOCAP_A).c_str());
}
else
{
- snprintf(throw_buff, sizeof(throw_buff), "Hit by a%s %s thrown by %s",
+ pbolt.aux_source = make_stringf("Hit by a%s %s thrown by %s",
(is_vowel(pbolt.name[0]) ? "n" : ""), pbolt.name.c_str(),
monster->name(DESC_NOCAP_A).c_str());
}
- pbolt.aux_source = throw_buff;
-
// Add everything up.
pbolt.hit = baseHit + random2avg(exHitBonus, 2) + ammoHitBonus;
pbolt.damage =
diff --git a/crawl-ref/source/ouch.cc b/crawl-ref/source/ouch.cc
index 93eaacd48b..1c7d94cf1f 100644
--- a/crawl-ref/source/ouch.cc
+++ b/crawl-ref/source/ouch.cc
@@ -1082,8 +1082,7 @@ void ouch(int dam, int death_source, kill_method_type death_type,
std::string damage_desc;
if (!see_source)
{
- snprintf(info, INFO_SIZE, "something (%d)", dam);
- damage_desc = info;
+ damage_desc = make_stringf("something (%d)", dam);
}
else
{
diff --git a/crawl-ref/source/place.cc b/crawl-ref/source/place.cc
index a07929b723..03fffbd370 100644
--- a/crawl-ref/source/place.cc
+++ b/crawl-ref/source/place.cc
@@ -114,21 +114,18 @@ std::string place_name( unsigned short place, bool long_name,
if (include_number && branches[branch].depth != 1)
{
- char buf[200];
if (long_name)
{
// decapitalise 'the'
if ( result.find("The") == 0 )
result[0] = 't';
- snprintf( buf, sizeof buf, "Level %d of %s",
- lev, result.c_str() );
+ result = make_stringf("Level %d of %s",
+ lev, result.c_str());
}
else if (lev)
- snprintf( buf, sizeof buf, "%s:%d", result.c_str(), lev );
+ result = make_stringf("%s:%d", result.c_str(), lev);
else
- snprintf( buf, sizeof buf, "%s:$", result.c_str() );
-
- result = buf;
+ result = make_stringf("%s:$", result.c_str());
}
return result;
}
diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc
index d117dc9238..1aac684a98 100644
--- a/crawl-ref/source/shopping.cc
+++ b/crawl-ref/source/shopping.cc
@@ -124,7 +124,6 @@ static void _list_shop_keys(const std::string &purchasable, bool viewing,
{
ASSERT(total_stock > 0);
- char buf[200];
const int numlines = get_number_of_lines();
cgotoxy(1, numlines - 1, GOTO_CRT);
@@ -159,7 +158,7 @@ static void _list_shop_keys(const std::string &purchasable, bool viewing,
pkeys = "[" + pkeys + "] Select Item to "
+ (viewing ? "Examine" : "Buy");
}
- snprintf(buf, sizeof buf,
+ formatted_string fs = formatted_string::parse_string(make_stringf(
"[<w>x</w>/<w>Esc</w>"
#ifdef USE_TILE
"/<w>R-Click</w>"
@@ -167,9 +166,8 @@ static void _list_shop_keys(const std::string &purchasable, bool viewing,
"] exit [<w>!</w>] %s %s%s",
(viewing ? "to select items " : "to examine items"),
pkeys.c_str(),
- shop_list.c_str());
+ shop_list.c_str()));
- formatted_string fs = formatted_string::parse_string(buf);
fs.cprintf("%*s", get_number_of_cols() - fs.length() - 1, "");
fs.display();
cgotoxy(1, numlines, GOTO_CRT);
@@ -2526,12 +2524,9 @@ void ShoppingListMenu::draw_title()
const char *verb = menu_action == ACT_EXECUTE ? "travel" :
menu_action == ACT_EXAMINE ? "examine" :
"delete";
- char buf[200];
- snprintf(buf, 200,
- "<lightgrey> [<w>a-z</w>: %s <w>?</w>/<w>!</w>: change action]",
- verb);
-
- draw_title_suffix(formatted_string::parse_string(buf), false);
+ draw_title_suffix(formatted_string::parse_string(make_stringf(
+ "<lightgrey> [<w>a-z</w>: %s <w>?</w>/<w>!</w>: change action]",
+ verb)), false);
}
}
diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc
index cb3a461b61..147dbc67d8 100644
--- a/crawl-ref/source/stash.cc
+++ b/crawl-ref/source/stash.cc
@@ -887,21 +887,15 @@ void ShopInfo::add_item(const item_def &sitem, unsigned price)
std::string ShopInfo::shop_item_name(const shop_item &si) const
{
- char shopitem[ITEMNAME_SIZE * 2];
-
const unsigned long oldflags = si.item.flags;
if (shoptype_identifies_stock(static_cast<shop_type>(this->shoptype)))
const_cast<shop_item&>(si).item.flags |= ISFLAG_IDENT_MASK;
- const std::string itemname = Stash::stash_item_name(si.item);
- snprintf(shopitem, sizeof shopitem, "%s (%u gold)",
- itemname.c_str(), si.price);
-
if (oldflags != si.item.flags)
const_cast<shop_item&>(si).item.flags = oldflags;
- return shopitem;
+ return make_stringf("%s (%u gold)", Stash::stash_item_name(si.item).c_str(), si.price);
}
std::string ShopInfo::shop_item_desc(const shop_item &si) const
@@ -1871,12 +1865,9 @@ void StashSearchMenu::draw_title()
title->quantity > 1? "es" : "",
sort_style);
- char buf[200];
- snprintf(buf, 200,
+ draw_title_suffix(formatted_string::parse_string(make_stringf(
"<lightgrey> [<w>a-z</w>: %s <w>?</w>/<w>!</w>: change action <w>/</w>: change sort]",
- menu_action == ACT_EXECUTE ? "travel" : "examine");
-
- draw_title_suffix(formatted_string::parse_string(buf), false);
+ menu_action == ACT_EXECUTE ? "travel" : "examine")), false);
}
}
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index 15defe291c..2e55a337ab 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -149,15 +149,13 @@ std::string make_file_time(time_t when)
{
if (tm *loc = TIME_FN(&when))
{
- char buf[25];
- snprintf(buf, sizeof buf, "%04d%02d%02d-%02d%02d%02d",
+ return make_stringf("%04d%02d%02d-%02d%02d%02d",
loc->tm_year + 1900,
loc->tm_mon + 1,
loc->tm_mday,
loc->tm_hour,
loc->tm_min,
loc->tm_sec);
- return (buf);
}
return ("");
}
diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc
index f0d1707dd6..ab60932b4f 100644
--- a/crawl-ref/source/tags.cc
+++ b/crawl-ref/source/tags.cc
@@ -603,23 +603,18 @@ bool unmarshallBoolean(reader &th)
// Saving the date as a string so we're not reliant on a particular epoch.
std::string make_date_string( time_t in_date )
{
- char buff[20];
-
if (in_date <= 0)
{
- buff[0] = 0;
- return (buff);
+ return ("");
}
struct tm *date = TIME_FN( &in_date );
- snprintf( buff, sizeof buff,
+ return make_stringf(
"%4d%02d%02d%02d%02d%02d%s",
date->tm_year + 1900, date->tm_mon, date->tm_mday,
date->tm_hour, date->tm_min, date->tm_sec,
((date->tm_isdst > 0) ? "D" : "S") );
-
- return (buff);
}
void marshallEnumVal(writer& wr, const enum_info *ei, int val)
diff --git a/crawl-ref/source/wiz-fsim.cc b/crawl-ref/source/wiz-fsim.cc
index 05ea5703dc..8a9929cdc8 100644
--- a/crawl-ref/source/wiz-fsim.cc
+++ b/crawl-ref/source/wiz-fsim.cc
@@ -300,15 +300,13 @@ static std::string _fsim_time_string()
struct tm *ltime = TIME_FN(&curr_time);
if (ltime)
{
- char buf[100];
- snprintf(buf, sizeof buf, "%4d%02d%02d/%2d:%02d:%02d",
+ return make_stringf("%4d%02d%02d/%2d:%02d:%02d",
ltime->tm_year + 1900,
ltime->tm_mon + 1,
ltime->tm_mday,
ltime->tm_hour,
ltime->tm_min,
ltime->tm_sec);
- return (buf);
}
return ("");
}