Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 42013 invoked from network); 10 Sep 2008 16:08:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Sep 2008 16:08:54 -0000 Received: (qmail 7071 invoked by uid 500); 10 Sep 2008 16:08:52 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 7047 invoked by uid 500); 10 Sep 2008 16:08:52 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 7033 invoked by uid 99); 10 Sep 2008 16:08:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Sep 2008 09:08:51 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Sep 2008 16:08:02 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C397C238896C; Wed, 10 Sep 2008 09:08:03 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r693878 - /harmony/enhanced/classlib/trunk/modules/nio_char/src/main/native/niochar/shared/additional/GB18030.c Date: Wed, 10 Sep 2008 16:08:02 -0000 To: commits@harmony.apache.org From: odeakin@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080910160803.C397C238896C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: odeakin Date: Wed Sep 10 09:08:02 2008 New Revision: 693878 URL: http://svn.apache.org/viewvc?rev=693878&view=rev Log: Fix errors from HARMONY-5976 ([classlib] Results of static analysis): - resultChar must be signed (jint) to handle error return code from getUnicodeFromBytes() - Fix unLinear() function so it does not return a pointer to deallocated stack memory. Modified: harmony/enhanced/classlib/trunk/modules/nio_char/src/main/native/niochar/shared/additional/GB18030.c Modified: harmony/enhanced/classlib/trunk/modules/nio_char/src/main/native/niochar/shared/additional/GB18030.c URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/native/niochar/shared/additional/GB18030.c?rev=693878&r1=693877&r2=693878&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/nio_char/src/main/native/niochar/shared/additional/GB18030.c (original) +++ harmony/enhanced/classlib/trunk/modules/nio_char/src/main/native/niochar/shared/additional/GB18030.c Wed Sep 10 09:08:02 2008 @@ -17,11 +17,12 @@ #include "GB18030.h" #include "hycomp.h" +#include "vmi.h" #define linear(b1, b2, b3, b4) ((((b1)*10+(b2))*126L+(b3))*10L+(b4)) -static jbyte * unLinear(jint lin) { - jbyte arr[] = {0, 0, 0, 0}; - jbyte *result = arr; +static jbyte* unLinear(JNIEnv *env, jint lin) { + PORT_ACCESS_FROM_ENV(env); + jbyte *result = hymem_allocate_memory(sizeof(jbyte)*4); lin-=linear((jbyte)0x81, (jbyte)0x30, (jbyte)0x81, (jbyte)0x30); result[3]=(jbyte)(0x30+lin%10); lin/=10; result[2]=(jbyte)(0x81+lin%126); lin/=126; @@ -1158,14 +1159,14 @@ return -1; } -static jbyte * getBytesFromUnicode(jint charValue) { +static jbyte* getBytesFromUnicode(JNIEnv *env, jint charValue) { int rangeCounter = 0; while(rangeCounter < sizeof(ranges)){ int startBytes = ranges[rangeCounter++]; int length = ranges[rangeCounter++]; int startChar = charValues[rangeCounter/2-1]; if(startChar<=charValue && charValue<=startChar+length) { - return unLinear(startBytes+(charValue-startChar)); + return unLinear(env, startBytes+(charValue-startChar)); } } return NULL; @@ -1182,9 +1183,9 @@ jchar *out = (*env)->GetCharArrayElements(env, outArr, NULL); jint *res = (*env)->GetIntArrayElements(env, result, NULL); - jint position = absolutePos; + jint resultChar, position = absolutePos; int i, variable; - jchar input, resultChar; + jchar input; jbyte b1, b2, b3, b4; for(i=0; i < bbremaining; i++) { if(res[1]==0) { @@ -1245,7 +1246,7 @@ break; } if (resultChar != 0) { - out[arrPosition++] = resultChar; res[1] -= 1; + out[arrPosition++] = (jchar)resultChar; res[1] -= 1; } else { if(!( (126 >= b2 && b2 >= 64) || (-2 >= b2 && b2 >= -128) || (57 >= b2 && b2 >= 48)) ) { res[0] = res[0]+2; @@ -1280,7 +1281,7 @@ resultChar = getUnicodeFromBytes(b1, b2, b3, b4); if(resultChar != -1) { res[0] -=4; - out[arrPosition++] = resultChar; res[1] -= 1; + out[arrPosition++] = (jchar)resultChar; res[1] -= 1; } else { res[2] = 4; res[3] = -1; (*env)->ReleaseCharArrayElements(env, outArr, out, 0); @@ -1324,7 +1325,7 @@ index = (int)input >> 8; index = encodeIndex[index]; while(index < 0) { - jbyte *arr = getBytesFromUnicode(in[arrayOffset+i]); + jbyte *arr = getBytesFromUnicode(env, in[arrayOffset+i]); if(arr!= NULL) { if(res[0]>=4) { *(jlong2addr(jbyte, outAddr) + position++) = (jbyte)arr[0]; @@ -1391,7 +1392,7 @@ } *(jlong2addr(jbyte, outAddr) + position++) = (jbyte)(resultChar & 0xFF); res[0] -= 1; } else { - jbyte *arr = getBytesFromUnicode(in[arrayOffset+i]); + jbyte *arr = getBytesFromUnicode(env, in[arrayOffset+i]); if(arr!= NULL) { if(res[0]>=4) { *(jlong2addr(jbyte, outAddr) + position++) = arr[0];