msvcrt: Ensure that old buffer contents are copied when allocating a growable pf_output buffer for the first time.
This commit is contained in:
parent
25764d79c0
commit
5c57185060
|
@ -429,19 +429,39 @@ static inline int pf_check_auto_grow(pf_output *out, unsigned delta)
|
|||
out->len = max(out->len * 2, out->used + delta);
|
||||
if (out->unicode)
|
||||
{
|
||||
WCHAR *ptr;
|
||||
|
||||
if (out->buf.W != out->grow.W)
|
||||
out->buf.W = MSVCRT_realloc(out->buf.W, out->len * sizeof(WCHAR));
|
||||
else
|
||||
out->buf.W = MSVCRT_malloc(out->len * sizeof(WCHAR));
|
||||
if (!out->buf.W) return -1;
|
||||
{
|
||||
if (!(ptr = MSVCRT_realloc(out->buf.W, out->len * sizeof(WCHAR))))
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (out->buf.A != out->grow.A)
|
||||
out->buf.A = MSVCRT_realloc(out->buf.A, out->len * sizeof(char));
|
||||
if (!(ptr = MSVCRT_malloc(out->len * sizeof(WCHAR))))
|
||||
return -1;
|
||||
memcpy(ptr, out->buf.W, out->used * sizeof(WCHAR));
|
||||
}
|
||||
|
||||
out->buf.W = ptr;
|
||||
}
|
||||
else
|
||||
out->buf.A = MSVCRT_malloc(out->len * sizeof(char));
|
||||
if (!out->buf.A) return -1;
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
if (out->buf.A != out->grow.A)
|
||||
{
|
||||
if (!(ptr = MSVCRT_realloc(out->buf.A, out->len * sizeof(char))))
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(ptr = MSVCRT_malloc(out->len * sizeof(char))))
|
||||
return -1;
|
||||
memcpy(ptr, out->buf.A, out->used * sizeof(char));
|
||||
}
|
||||
|
||||
out->buf.A = ptr;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue