You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/08/06 20:31:39 UTC

svn commit: r801762 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_string.h shared/string.c

Author: mturk
Date: Thu Aug  6 18:31:38 2009
New Revision: 801762

URL: http://svn.apache.org/viewvc?rev=801762&view=rev
Log:
Make our strdup having double zero terminating chars

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h?rev=801762&r1=801761&r2=801762&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h Thu Aug  6 18:31:38 2009
@@ -144,7 +144,8 @@
 
 /**
  * Apache's "replacement" for the strdup() function that throws
- * the java.lang.OutOfMemoryError in case of failure.
+ * the java.lang.OutOfMemoryError in case of failure and has double
+ * zero temination.
  * @param env Current JNI environment.
  * @param file Source file where the function was called
  * @param line Source file line where the function was called
@@ -156,7 +157,8 @@
 
 /**
  * Apache's "replacement" for the wcsdup() function that throws
- * the java.lang.OutOfMemoryError in case of failure.
+ * the java.lang.OutOfMemoryError in case of failure and has double
+ * zero temination.
  * @param env Current JNI environment.
  * @param file Source file where the function was called
  * @param line Source file line where the function was called

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=801762&r1=801761&r2=801762&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Thu Aug  6 18:31:38 2009
@@ -579,7 +579,8 @@
 {
     char *d = NULL;
     if (s) {
-        d = strdup(s);
+        size_t size = strlen(s);
+        d = malloc(size + 2);
         if (!d) {
             int err = ACR_GET_OS_ERROR();
             if (_E == NULL)
@@ -587,6 +588,30 @@
             if (_E != NULL)
                 ACR_ThrowException(_E, file, line, ACR_EX_ENOMEM, err);
         }
+        memcpy(d, s, size);
+        d[size++] = '\0';
+        d[size]   = '\0';
+    }
+    return d;
+}
+
+ACR_DECLARE(wchar_t *) ACR_StrdupW(JNIEnv *_E, const char *file, int line,
+                                   const wchar_t *s)
+{
+    wchar_t *d = NULL;
+    if (s) {
+        size_t size = wcslen(s);
+        d = malloc((size + 2) * sizeof(wchar_t));
+        if (!d) {
+            int err = ACR_GET_OS_ERROR();
+            if (_E == NULL)
+                _E = ACR_GetJNIEnv();
+            if (_E != NULL)
+                ACR_ThrowException(_E, file, line, ACR_EX_ENOMEM, err);
+        }
+        memcpy(d, s, size * sizeof(wchar_t));
+        d[size++] = L'\0';
+        d[size]   = L'\0';
     }
     return d;
 }