提交 e58f7ec0 编写于 作者: M Max Bruckner

ensure: Fix potential overflow of size_t

This could only happen if the maximum SIZE_T is not at least 2 times
bigger than INT_MAX. Not sure if this can happen on real systems, but
better be safe then sorry.
上级 4bfb8800
......@@ -270,8 +270,7 @@ static unsigned char* ensure(printbuffer * const p, size_t needed, const interna
}
/* calculate new buffer size */
newsize = needed * 2;
if (newsize > INT_MAX)
if (newsize > (INT_MAX / 2))
{
/* overflow of int, use INT_MAX if possible */
if (needed <= INT_MAX)
......@@ -283,6 +282,10 @@ static unsigned char* ensure(printbuffer * const p, size_t needed, const interna
return NULL;
}
}
else
{
newsize = needed * 2;
}
if (hooks->reallocate != NULL)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册