[kaffe] CharToByteIconv dumps core when used for SHIFT_JIS

Ito Kazumitsu ito.kazumitsu at hitachi-cable.co.jp
Tue Apr 29 17:42:01 PDT 2003


In message "[kaffe] CharToByteIconv dumps core when used for SHIFT_JIS"
    on 03/04/28, Ito Kazumitsu <ito.kazumitsu at hitachi-cable.co.jp> writes:

> I found a case where CharToByteIconv dumps core when used for SHIFT_JIS.

> A patch to CharToByteIconv.c
> ============================
> --- libraries/clib/native/CharToByteIconv.c.orig	Tue Apr 16 04:14:50 2002
> +++ libraries/clib/native/CharToByteIconv.c	Mon Apr 28 16:24:27 2003
> @@ -76,6 +76,8 @@
>      char	*buffer;
>  #endif
>  
> +    if (icv_inlen == 0) return 0;
> +
>  #ifndef WORDS_BIGENDIAN
>      buffer = KMALLOC (icv_inlen);
>      if (!buffer) {
> 

The following patch also helps solve the problem.

--- libraries/clib/native/CharToByteIconv.c.orig	Tue Apr 16 04:14:50 2002
+++ libraries/clib/native/CharToByteIconv.c	Wed Apr 30 09:17:14 2003
@@ -77,21 +77,28 @@
 #endif
 
 #ifndef WORDS_BIGENDIAN
-    buffer = KMALLOC (icv_inlen);
-    if (!buffer) {
-	jclass oom;
+    if (icv_inlen > 0) {
+        buffer = KMALLOC (icv_inlen);
+        if (!buffer) {
+	    jclass oom;
 
-	(*env)->ReleaseCharArrayElements(env, fromChars, jc, JNI_ABORT);
-	(*env)->ReleaseByteArrayElements(env, toBytes, jb, 0);
-	oom = (*env)->FindClass(env, "java.lang.OutOfMemory");
-	(*env)->ThrowNew(env, oom, "iconv()");
+	    (*env)->ReleaseCharArrayElements(env, fromChars, jc, JNI_ABORT);
+	    (*env)->ReleaseByteArrayElements(env, toBytes, jb, 0);
+	    oom = (*env)->FindClass(env, "java.lang.OutOfMemory");
+	    (*env)->ThrowNew(env, oom, "iconv()");
+        }
+        swab (icv_in, buffer, icv_inlen);
+        icv_in = buffer;
+    }
+    else {
+        buffer = NULL;
     }
-    swab (icv_in, buffer, icv_inlen);
-    icv_in = buffer;
 #endif
     ret = iconv (cd, &icv_in, &icv_inlen, &icv_out, &icv_outlen);
 #ifndef WORDS_BIGENDIAN
-    KFREE (buffer);
+    if (buffer) {
+        KFREE (buffer);
+    }
 #endif
     if (icv_inlen > 0) {
 	/* In case we have some bytes left, save them */




More information about the kaffe mailing list