summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-27 13:41:55 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-27 13:41:55 +0000
commit91bc3928fb0c255f3ebdc3275740bb3442ecab96 (patch)
treef55b1e1878dfe517786dda5b86e04197848458c2
parentf65612ebae127c790528e9699dde9125a93d0cb4 (diff)
downloadcrawl-ref-91bc3928fb0c255f3ebdc3275740bb3442ecab96.tar.gz
crawl-ref-91bc3928fb0c255f3ebdc3275740bb3442ecab96.zip
Fixed hiscores segfaults (reprise for 0.1.4).
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.1.4@501 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/hiscores.cc33
-rw-r--r--crawl-ref/source/hiscores.h4
-rw-r--r--crawl-ref/source/ouch.cc9
3 files changed, 20 insertions, 26 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 ;)
diff --git a/crawl-ref/source/hiscores.h b/crawl-ref/source/hiscores.h
index 93b22e660d..f8d7841fe7 100644
--- a/crawl-ref/source/hiscores.h
+++ b/crawl-ref/source/hiscores.h
@@ -28,8 +28,8 @@ void hiscores_print_list( int display_count = -1, int format = SCORE_TERSE );
/* ***********************************************************************
* called from: ouch hiscores
* *********************************************************************** */
-void hiscores_format_single( char *buffer, const scorefile_entry &se );
-void hiscores_format_single_long( char *buffer, const scorefile_entry &se,
+std::string hiscores_format_single( const scorefile_entry &se );
+std::string hiscores_format_single_long( const scorefile_entry &se,
bool verbose = false );
#endif // HISCORES_H
diff --git a/crawl-ref/source/ouch.cc b/crawl-ref/source/ouch.cc
index 4cc78e65d8..f73f3c20da 100644
--- a/crawl-ref/source/ouch.cc
+++ b/crawl-ref/source/ouch.cc
@@ -891,15 +891,12 @@ void end_game( struct scorefile_entry &se )
cprintf( "Goodbye, %s.", you.your_name );
cprintf( EOL EOL " " ); // Space padding where # would go in list format
- char scorebuff[ HIGHSCORE_SIZE ];
- hiscores_format_single_long( scorebuff, se, true );
- // truncate
- scorebuff[ HIGHSCORE_SIZE - 1 ] = 0;
+ std::string hiscore = hiscores_format_single_long( se, true );
- const int lines = count_occurrences(scorebuff, EOL) + 1;
+ const int lines = count_occurrences(hiscore, EOL) + 1;
- cprintf( scorebuff );
+ cprintf( "%s", hiscore.c_str() );
cprintf( EOL "Best Crawlers -" EOL );