summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/cio.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2011-04-03 23:12:51 +0200
committerAdam Borowski <kilobyte@angband.pl>2011-04-04 00:23:48 +0200
commit3d6dd413fe21a3ca0f0d71daa18f12bc7faa9694 (patch)
treea89cd8fad7e9a45a1b6824f8cf0a1761ce03bd46 /crawl-ref/source/cio.cc
parent09b5222a26359a00371d394ac2fa9d09d6a176e5 (diff)
downloadcrawl-ref-3d6dd413fe21a3ca0f0d71daa18f12bc7faa9694.tar.gz
crawl-ref-3d6dd413fe21a3ca0f0d71daa18f12bc7faa9694.zip
Fix nowrap_eol_cprintf() overshooting in some cases.
It's used only in four places, none of them can be actually triggered currently, but might be in the future.
Diffstat (limited to 'crawl-ref/source/cio.cc')
-rw-r--r--crawl-ref/source/cio.cc40
1 files changed, 4 insertions, 36 deletions
diff --git a/crawl-ref/source/cio.cc b/crawl-ref/source/cio.cc
index b6eda4bf36..8dbf2e3d0b 100644
--- a/crawl-ref/source/cio.cc
+++ b/crawl-ref/source/cio.cc
@@ -152,51 +152,19 @@ void cursorxy(int x, int y)
}
// cprintf that stops outputting when wrapped
-// Conceptually very similar to wrapcprintf()
-int nowrapcprintf(int wrapcol, const char *s, ...)
-{
- char buf[1000]; // Hard max
-
- va_list args;
- va_start(args, s);
- // XXX: If snprintf isn't available, vsnprintf probably isn't, either.
- const int len = vsnprintf(buf, sizeof buf, s, args);
- va_end(args);
-
- // Sanity checking to prevent buffer overflows
- const int maxlen = std::min(std::max(wrapcol + 1 - wherex(), 0), len);
-
- // Force the string to terminate at maxlen
- buf[maxlen] = 0;
-
- cprintf("%s", buf);
- return std::min(len, maxlen);
-}
-
-// convenience wrapper (hah) for nowrapcprintf
-// FIXME: should pass off to nowrapcprintf() instead of doing it manually
-int nowrap_eol_cprintf(const char *s, ...)
+void nowrap_eol_cprintf(const char *s, ...)
{
const int wrapcol = get_number_of_cols() - 1;
- char buf[1000]; // Hard max
va_list args;
va_start(args, s);
- // XXX: If snprintf isn't available, vsnprintf probably isn't, either.
- const int len = vsnprintf(buf, sizeof buf, s, args);
+ std::string buf = vmake_stringf(s, args);
va_end(args);
- // Sanity checking to prevent buffer overflows
- const int maxlen = std::min(std::max(wrapcol + 1 - wherex(), 0), len);
-
- // Force the string to terminate at maxlen
- buf[maxlen] = 0;
-
- cprintf("%s", buf);
- return std::min(len, maxlen);
+ cprintf("%s", chop_string(buf, std::max(wrapcol + 1 - wherex(), 0), false).c_str());
}
-// cprintf that knows how to wrap down lines (primitive, but what the heck)
+// cprintf that knows how to wrap down lines
void wrapcprintf(int wrapcol, const char *s, ...)
{
va_list args;