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 getUnico
deFromBytes()
- Fix unLinear() function so it does not return a pointer to deallocated sta
ck 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/ni
ochar/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=69387
7&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 >= -12
8) || (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)(result
Char & 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];