Andrew Nguyen : msvcrt: Ensure that old buffer contents are copied when allocating a growable pf_output buffer for the first time .

Alexandre Julliard julliard at winehq.org
Mon Apr 4 10:10:57 CDT 2011


Module: wine
Branch: master
Commit: 5c57185060ce9863119d310ed380772866cb21bb
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=5c57185060ce9863119d310ed380772866cb21bb

Author: Andrew Nguyen <anguyen at codeweavers.com>
Date:   Sun Apr  3 23:05:20 2011 -0500

msvcrt: Ensure that old buffer contents are copied when allocating a growable pf_output buffer for the first time.

---

 dlls/msvcrt/wcs.c |   32 ++++++++++++++++++++++++++------
 1 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c
index a7c7a77..fc77656 100644
--- a/dlls/msvcrt/wcs.c
+++ b/dlls/msvcrt/wcs.c
@@ -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));
+            {
+                if (!(ptr = MSVCRT_realloc(out->buf.W, out->len * sizeof(WCHAR))))
+                    return -1;
+            }
             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
         {
+            char *ptr;
+
             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
-                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;




More information about the wine-cvs mailing list