fix out-of-bounds memory access in to_string

This commit is contained in:
Arvid Norberg 2012-02-16 03:54:56 +00:00
parent 35ea214124
commit 91df5d1894
1 changed files with 2 additions and 2 deletions

View File

@ -71,7 +71,7 @@ namespace libtorrent
boost::array<char, 3 + std::numeric_limits<size_type>::digits10> to_string(size_type n)
{
boost::array<char, 3 + std::numeric_limits<size_type>::digits10> ret;
char *p = &ret.back();;
char *p = &ret.back();
*p = '\0';
unsigned_size_type un = n;
if (n < 0) un = -un;
@ -80,7 +80,7 @@ namespace libtorrent
un /= 10;
} while (un);
if (n < 0) *--p = '-';
std::memmove(&ret.front(), p, sizeof(ret.elems));
std::memmove(&ret[0], p, &ret.back() - p);
return ret;
}