diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-27 01:46:16 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-27 01:46:16 -0400 |
commit | 316b854676aed1a7ae5d6a914d6b52eb6da4bb87 (patch) | |
tree | 0493ef79756a3ac4be6cdc31d9ebb5b0dc428ce9 /src/unistring.h | |
parent | 0ed57916cfcf103a141e5edfd75bf547c03c04ad (diff) | |
download | fork-ledger-316b854676aed1a7ae5d6a914d6b52eb6da4bb87.tar.gz fork-ledger-316b854676aed1a7ae5d6a914d6b52eb6da4bb87.tar.bz2 fork-ledger-316b854676aed1a7ae5d6a914d6b52eb6da4bb87.zip |
Fixed a buffer overrun
Diffstat (limited to 'src/unistring.h')
-rw-r--r-- | src/unistring.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/unistring.h b/src/unistring.h index b1c46cb3..cadf82fe 100644 --- a/src/unistring.h +++ b/src/unistring.h @@ -48,6 +48,8 @@ #include "utils.h" +namespace ledger { + /** * @class unistring * @@ -68,7 +70,7 @@ public: const char * p = input.c_str(); std::size_t len = input.length(); - //assert(utf8::is_valid(p, p + len)); + assert(utf8::is_valid(p, p + len)); utf8::utf8to32(p, p + len, std::back_inserter(utf32chars)); } ~unistring() { @@ -83,9 +85,14 @@ public: const std::size_t len = 0) const { std::string utf8result; - utf8::utf32to8(utf32chars.begin() + begin, - utf32chars.begin() + begin + (len ? len : length()), - std::back_inserter(utf8result)); + std::size_t this_len = length(); + assert(begin <= this_len); + assert(begin + len <= this_len); + if (this_len) + utf8::utf32to8(utf32chars.begin() + begin, + utf32chars.begin() + begin + + (len ? (len > this_len ? this_len : len) : this_len), + std::back_inserter(utf8result)); return utf8result; } }; @@ -108,4 +115,6 @@ inline void justify(std::ostream& out, out << str; } +} // namespace ledger + #endif // _UNISTRING_H |