Commit 5c571850 authored by Andrew Nguyen's avatar Andrew Nguyen Committed by Alexandre Julliard

msvcrt: Ensure that old buffer contents are copied when allocating a growable…

msvcrt: Ensure that old buffer contents are copied when allocating a growable pf_output buffer for the first time.
parent 25764d79
...@@ -429,19 +429,39 @@ static inline int pf_check_auto_grow(pf_output *out, unsigned delta) ...@@ -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); out->len = max(out->len * 2, out->used + delta);
if (out->unicode) if (out->unicode)
{ {
WCHAR *ptr;
if (out->buf.W != out->grow.W) if (out->buf.W != out->grow.W)
out->buf.W = MSVCRT_realloc(out->buf.W, out->len * sizeof(WCHAR)); {
if (!(ptr = MSVCRT_realloc(out->buf.W, out->len * sizeof(WCHAR))))
return -1;
}
else else
out->buf.W = MSVCRT_malloc(out->len * sizeof(WCHAR)); {
if (!out->buf.W) return -1; if (!(ptr = MSVCRT_malloc(out->len * sizeof(WCHAR))))
return -1;
memcpy(ptr, out->buf.W, out->used * sizeof(WCHAR));
}
out->buf.W = ptr;
} }
else else
{ {
char *ptr;
if (out->buf.A != out->grow.A) if (out->buf.A != out->grow.A)
out->buf.A = MSVCRT_realloc(out->buf.A, out->len * sizeof(char)); {
if (!(ptr = MSVCRT_realloc(out->buf.A, out->len * sizeof(char))))
return -1;
}
else else
out->buf.A = MSVCRT_malloc(out->len * sizeof(char)); {
if (!out->buf.A) return -1; 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; return 0;
......
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