Commit 1f44278e authored by Dimitri van Heesch's avatar Dimitri van Heesch

Avoid accessing uninitialized memory in fileToString

parent 5386a768
......@@ -33,7 +33,7 @@ class BufStr
BufStr(int size)
: m_size(size), m_writeOffset(0), m_spareRoom(10240), m_buf(0)
{
m_buf = (char *)malloc(size);
m_buf = (char *)calloc(size,1);
}
~BufStr()
{
......@@ -62,12 +62,17 @@ class BufStr
}
void resize( uint newlen )
{
uint oldsize = m_size;
m_size=newlen;
if (m_writeOffset>=m_size) // offset out of range -> enlarge
{
m_size=m_writeOffset+m_spareRoom;
}
m_buf = (char *)realloc(m_buf,m_size);
if (m_size>oldsize)
{
memset(m_buf+oldsize,0,m_size-oldsize);
}
}
int size() const
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment