stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vi...@apache.org
Subject svn commit: r648064 - in /stdcxx/trunk/tests/src: fmt_defs.h printf.cpp
Date Mon, 14 Apr 2008 23:49:13 GMT
Author: vitek
Date: Mon Apr 14 16:49:11 2008
New Revision: 648064

URL: http://svn.apache.org/viewvc?rev=648064&view=rev
Log:

2008-04-14  Travis Vitek  <vitek@roguewave.com>

	STDCXX-857
	* tests/src/printf.cpp: Revert r647908 which indirectly caused
	memory leaks in the test driver and several tests.
	* tests/src/fmt_defs.h: Ditto.

Modified:
    stdcxx/trunk/tests/src/fmt_defs.h
    stdcxx/trunk/tests/src/printf.cpp

Modified: stdcxx/trunk/tests/src/fmt_defs.h
URL: http://svn.apache.org/viewvc/stdcxx/trunk/tests/src/fmt_defs.h?rev=648064&r1=648063&r2=648064&view=diff
==============================================================================
--- stdcxx/trunk/tests/src/fmt_defs.h (original)
+++ stdcxx/trunk/tests/src/fmt_defs.h Mon Apr 14 16:49:11 2008
@@ -59,7 +59,6 @@
     size_t  *pbufsize;   // pointer to the size of the buffer
     size_t   maxsize;    // maximum not-to-exceed size
     size_t   endoff;     // offset of the last character
-    size_t   owned;      // buffer is owned by caller, don't free it
 };
 
 /********************************************************************/

Modified: stdcxx/trunk/tests/src/printf.cpp
URL: http://svn.apache.org/viewvc/stdcxx/trunk/tests/src/printf.cpp?rev=648064&r1=648063&r2=648064&view=diff
==============================================================================
--- stdcxx/trunk/tests/src/printf.cpp (original)
+++ stdcxx/trunk/tests/src/printf.cpp Mon Apr 14 16:49:11 2008
@@ -450,24 +450,26 @@
 
         size_t guardsize = sizeof guard - 1;
 
-        size_t newbufsize = *buf.pbufsize * 2;
+        size_t newbufsize = *buf.pbufsize * 2 + guardsize;
 
-        const size_t required = buflen + len;
-        if (newbufsize < required)
-            newbufsize = required * 2;
+        if (newbufsize <= buflen + len + guardsize)
+            newbufsize = 2 * (buflen + len + 1) + guardsize;
 
         // prevent buffer size from exceeding the maximum
         if (buf.maxsize < newbufsize)
             newbufsize = buf.maxsize;
 
-        if (newbufsize < required) {
+        if (newbufsize < buflen + len + guardsize)
+            guardsize = 0;
+
+        if (newbufsize < buflen + len + guardsize) {
 #ifdef ENOMEM
             errno = ENOMEM;
 #endif   // ENOMEM
             return 0;
         }
 
-        char* const newbuf = (char*)malloc (newbufsize + guardsize);
+        char* const newbuf = (char*)malloc (newbufsize);
 
         // return 0 on failure to allocate, let caller deal with it
         if (0 == newbuf)
@@ -476,21 +478,17 @@
         memcpy (newbuf, *buf.pbuf, buflen);
 
         // append a guard block to the end of the buffer
-        memcpy (newbuf + newbufsize, guard, guardsize);
+        memcpy (newbuf + newbufsize - guardsize, guard, guardsize);
 
-        if (*buf.pbuf && !buf.owned) {
+        if (*buf.pbuf) {
             // verify that we didn't write past the end of the buffer
             RW_ASSERT (0 == memcmp (*buf.pbuf + *buf.pbufsize,
                                     guard, guardsize));
-
             free (*buf.pbuf);
         }
 
         *buf.pbuf     = newbuf;
-        *buf.pbufsize = newbufsize;
-
-        // we allocated the buffer, so we can free it
-        buf.owned = 0;
+        *buf.pbufsize = newbufsize - guardsize;
     }
 
     if (0 != str) {
@@ -960,7 +958,7 @@
     if (0 == pbufsize)
         pbufsize = &default_bufsize;
 
-    Buffer buf = { pbuf, pbufsize, _RWSTD_SIZE_MAX, 0, 1 };
+    Buffer buf = { pbuf, pbufsize, _RWSTD_SIZE_MAX, 0 };
 
     // save the initial value of `pbuf'
     char* const pbuf_save = *buf.pbuf;
@@ -1997,7 +1995,7 @@
                 size_t localbufsize = sizeof elemstr;
 
                 Buffer bufspec = {
-                    &localbuf, &localbufsize, sizeof elemstr, 0, 1
+                    &localbuf, &localbufsize, sizeof elemstr, 0
                 };
 
                 *localbuf = '\0';
@@ -2055,7 +2053,7 @@
                 size_t localbufsize = sizeof elemstr;
 
                 Buffer bufspec = {
-                    &localbuf, &localbufsize, sizeof elemstr, 0, 1
+                    &localbuf, &localbufsize, sizeof elemstr, 0
                 };
 
                 *localbuf = '\0';
@@ -2985,7 +2983,7 @@
         const char* const fmt = VA_ARG (*pva, char*);
 
         size_t dummy_size = 0;   // unused
-        Buffer tmpbuf = { &fmtword, &dummy_size, _RWSTD_SIZE_MAX, 0, 1 };
+        Buffer tmpbuf = { &fmtword, &dummy_size, _RWSTD_SIZE_MAX, 0 };
         const int len = _rw_pvasnprintf (tmpbuf, fmt, pva);
         if (len < 0)
             return -1;



Mime
View raw message