summaryrefslogtreecommitdiff
path: root/src/format.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-27 01:46:16 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-27 01:46:16 -0400
commit316b854676aed1a7ae5d6a914d6b52eb6da4bb87 (patch)
tree0493ef79756a3ac4be6cdc31d9ebb5b0dc428ce9 /src/format.cc
parent0ed57916cfcf103a141e5edfd75bf547c03c04ad (diff)
downloadfork-ledger-316b854676aed1a7ae5d6a914d6b52eb6da4bb87.tar.gz
fork-ledger-316b854676aed1a7ae5d6a914d6b52eb6da4bb87.tar.bz2
fork-ledger-316b854676aed1a7ae5d6a914d6b52eb6da4bb87.zip
Fixed a buffer overrun
Diffstat (limited to 'src/format.cc')
-rw-r--r--src/format.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/format.cc b/src/format.cc
index a9d867bd..69c0b42f 100644
--- a/src/format.cc
+++ b/src/format.cc
@@ -335,8 +335,13 @@ string format_t::truncate(const unistring& ustr, std::size_t width,
if (newlen > width) {
unistring temp(*i);
- result << temp.extract(0, account_abbrev_length) << ":";
- newlen -= temp.length() - account_abbrev_length;
+ if (temp.length() > static_cast<std::size_t>(account_abbrev_length)) {
+ result << temp.extract(0, account_abbrev_length) << ":";
+ newlen -= temp.length() - account_abbrev_length;
+ } else {
+ result << temp.extract() << ":";
+ newlen -= temp.length();
+ }
} else {
result << *i << ":";
}
@@ -346,7 +351,8 @@ string format_t::truncate(const unistring& ustr, std::size_t width,
// Even abbreviated its too big to show the last account, so
// abbreviate all but the last and truncate at the beginning.
unistring temp(result.str());
- buf << ".." << temp.extract(temp.length() - width - 2, width - 2);
+ assert(temp.length() > width - 2);
+ buf << ".." << temp.extract(temp.length() - (width - 2), width - 2);
} else {
buf << result.str();
}