properly throw on failing to allocate memory in buffer and bitfield
This commit is contained in:
parent
a3a06ca45c
commit
3218931495
|
@ -309,14 +309,20 @@ namespace libtorrent
|
||||||
const int b = (bits + 31) / 32;
|
const int b = (bits + 31) / 32;
|
||||||
if (m_buf)
|
if (m_buf)
|
||||||
{
|
{
|
||||||
m_buf = static_cast<boost::uint32_t*>(std::realloc(m_buf-1, (b+1) * 4));
|
boost::uint32_t* tmp = static_cast<boost::uint32_t*>(std::realloc(m_buf-1, (b+1) * 4));
|
||||||
m_buf = m_buf + 1;
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
if (tmp == NULL) throw std::bad_alloc();
|
||||||
|
#endif
|
||||||
|
m_buf = tmp + 1;
|
||||||
m_buf[-1] = bits;
|
m_buf[-1] = bits;
|
||||||
}
|
}
|
||||||
else if (bits > 0)
|
else if (bits > 0)
|
||||||
{
|
{
|
||||||
m_buf = static_cast<boost::uint32_t*>(std::malloc((b+1) * 4));
|
boost::uint32_t* tmp = static_cast<boost::uint32_t*>(std::malloc((b+1) * 4));
|
||||||
m_buf = m_buf + 1;
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
if (tmp == NULL) throw std::bad_alloc();
|
||||||
|
#endif
|
||||||
|
m_buf = tmp + 1;
|
||||||
m_buf[-1] = bits;
|
m_buf[-1] = bits;
|
||||||
}
|
}
|
||||||
else if (m_buf != NULL)
|
else if (m_buf != NULL)
|
||||||
|
|
|
@ -217,7 +217,11 @@ public:
|
||||||
TORRENT_ASSERT(n > 0);
|
TORRENT_ASSERT(n > 0);
|
||||||
TORRENT_ASSERT(n < 0xffffffffu);
|
TORRENT_ASSERT(n < 0xffffffffu);
|
||||||
|
|
||||||
m_begin = static_cast<char*>(std::realloc(m_begin, n));
|
char* tmp = static_cast<char*>(std::realloc(m_begin, n));
|
||||||
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
if (tmp == NULL) throw std::bad_alloc();
|
||||||
|
#endif
|
||||||
|
m_begin = tmp;
|
||||||
m_capacity = boost::uint32_t(n);
|
m_capacity = boost::uint32_t(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue