summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/hiscores.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-27 13:23:20 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-27 13:23:20 +0000
commit7126d90fe0565292ef24bc7d7c0474f988f5f41f (patch)
tree33c09f550f3aa210902b171a007818772e381acf /crawl-ref/source/hiscores.cc
parentb7a932776480b974879b0e4de971c98bb90b8f0b (diff)
downloadcrawl-ref-7126d90fe0565292ef24bc7d7c0474f988f5f41f.tar.gz
crawl-ref-7126d90fe0565292ef24bc7d7c0474f988f5f41f.zip
Fixed hiscores buffer segfault madness.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@498 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/hiscores.cc')
-rw-r--r--crawl-ref/source/hiscores.cc33
1 files changed, 15 insertions, 18 deletions
diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc
index bb15621d36..1e5fafe507 100644
--- a/crawl-ref/source/hiscores.cc
+++ b/crawl-ref/source/hiscores.cc
@@ -214,25 +214,26 @@ void hiscores_print_list( int display_count, int format )
else
cprintf("%s", info);
+ std::string entry;
// format the entry
if (format == SCORE_TERSE)
{
- hiscores_format_single( info, hs_list[i] );
+ entry = hiscores_format_single( hs_list[i] );
// truncate if we want short format
- info[75] = 0;
+ if (entry.length() > 75)
+ entry = entry.substr(0, 75);
}
else
{
- hiscores_format_single_long( info, hs_list[i],
+ entry = hiscores_format_single_long( hs_list[i],
(format == SCORE_VERBOSE) );
}
- // print entry
- strcat(info, EOL);
+ entry += EOL;
if(use_printf)
- printf("%s", info);
+ printf("%s", entry.c_str());
else
- cprintf("%s", info);
+ cprintf("%s", entry.c_str());
if (i == newest_entry && !use_printf)
textcolor(LIGHTGREY);
@@ -254,11 +255,9 @@ static const char *const range_type_verb( const char *const aux )
return ("blasted"); // spells, wands
}
-void hiscores_format_single(char *buf, const scorefile_entry &se)
+std::string hiscores_format_single(const scorefile_entry &se)
{
- std::string line = se.hiscore_line(scorefile_entry::DDV_ONELINE);
- strncpy(buf, line.c_str(), INFO_SIZE);
- buf[INFO_SIZE - 1] = 0;
+ return se.hiscore_line(scorefile_entry::DDV_ONELINE);
}
static bool hiscore_same_day( time_t t1, time_t t2 )
@@ -289,16 +288,14 @@ static std::string hiscore_newline_string()
return (EOL " ");
}
-void hiscores_format_single_long( char *buf, const scorefile_entry &se,
- bool verbose )
+std::string hiscores_format_single_long( const scorefile_entry &se,
+ bool verbose )
{
- std::string line =
- se.hiscore_line(
+ return se.hiscore_line(
verbose?
scorefile_entry::DDV_VERBOSE
: scorefile_entry::DDV_NORMAL );
- strncpy(buf, line.c_str(), HIGHSCORE_SIZE);
- buf[HIGHSCORE_SIZE - 1] = 0;
+
}
// --------------------------------------------------------------------------
@@ -1510,7 +1507,7 @@ scorefile_entry::character_description(death_desc_verbosity verbosity) const
bool verbose = verbosity == DDV_VERBOSE;
char scratch[INFO_SIZE];
- char buf[INFO_SIZE];
+ char buf[HIGHSCORE_SIZE];
std::string desc;
// Please excuse the following bit of mess in the name of flavour ;)