You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by wr...@apache.org on 2011/04/14 09:22:07 UTC

svn commit: r1092026 - /apr/apr/trunk/misc/win32/start.c

Author: wrowe
Date: Thu Apr 14 07:22:06 2011
New Revision: 1092026

URL: http://svn.apache.org/viewvc?rev=1092026&view=rev
Log:
Fix VC10 release build running on Windows7/Server 2008 

Submitted by: Steve Hay <SteveHay planit.com>

Forward ports: 1092025

Modified:
    apr/apr/trunk/misc/win32/start.c

Modified: apr/apr/trunk/misc/win32/start.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/misc/win32/start.c?rev=1092026&r1=1092025&r2=1092026&view=diff
==============================================================================
--- apr/apr/trunk/misc/win32/start.c (original)
+++ apr/apr/trunk/misc/win32/start.c Thu Apr 14 07:22:06 2011
@@ -45,7 +45,9 @@ static int warrsztoastr(const char * con
     apr_size_t totlen;
     apr_size_t newlen;
     apr_size_t wsize;
-    char **newarr;
+    char **env;
+    char *pstrs;
+    char *strs;
     int arg;
 
     if (args < 0) {
@@ -55,37 +57,40 @@ static int warrsztoastr(const char * con
     }
     wsize = 1 + wch - arrsz;
 
-    newarr = apr_malloc_dbg((args + 1) * sizeof(char *),
-                            __FILE__, __LINE__);
-
-    /* This is a safe max allocation, we will realloc after
-     * processing and return the excess to the free store.
+    /* This is a safe max allocation, we will alloc each
+     * string exactly after processing and return this
+     * temporary buffer to the free store.
      * 3 ucs bytes hold any single wchar_t value (16 bits)
      * 4 ucs bytes will hold a wchar_t pair value (20 bits)
      */
     newlen = totlen = wsize * 3 + 1;
-    newarr[0] = apr_malloc_dbg(newlen * sizeof(char),
-                               __FILE__, __LINE__);
+    pstrs = strs = apr_malloc_dbg(newlen * sizeof(char),
+                                  __FILE__, __LINE__);
 
-    (void)apr_conv_ucs2_to_utf8(arrsz, &wsize,
-                                newarr[0], &newlen);
+    (void)apr_conv_ucs2_to_utf8(arrsz, &wsize, strs, &newlen);
 
     assert(newlen && !wsize);
-    /* Return to the free store if the heap realloc is the least bit optimized
-     */
-    newarr[0] = apr_realloc_dbg(newarr[0], totlen - newlen,
-                                __FILE__, __LINE__);
 
-    for (arg = 1; arg < args; ++arg) {
-        newarr[arg] = newarr[arg - 1] + 2;
-        while (*(newarr[arg]++)) {
-            /* continue */;
-        }
+    *retarr = env = apr_malloc_dbg((args + 1) * sizeof(char*),
+                                   __FILE__, __LINE__);
+    for (arg = 0; arg < args; ++arg) {
+        char* p = pstrs;
+        int len = 0;
+        while (*p++)
+            ++len;
+        len += 1;
+
+        *env = apr_malloc_dbg(len * sizeof(char),
+                              __FILE__, __LINE__);
+        memcpy(*env, pstrs, len * sizeof(char));
+
+        pstrs += len;
+        ++env;
     }
 
-    newarr[arg] = NULL;
+    *env = NULL;
+    free(strs);
 
-    *retarr = newarr;
     return args;
 }
 #endif