fix bug#116315: don't pass null char into JRI_NewPlatformString

git-svn-id: svn://10.0.0.236/trunk@1439 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
selmer 1998-05-12 02:03:33 +00:00
parent f810b7168d
commit 68b64888ae

View File

@ -521,37 +521,21 @@ java_lang_String * getRegElement(JRIEnv *env,
}
}
// long length = 1 + strlen(value); // 1 extra for the null char -- WRONG!
// Don't add the 1 to the length here, do it in the malloc
long length = strlen(value);
long bufLen = (extendLen ? len : lenShort);
if (extendLen == TRUE) {
rtnValue = (char *)malloc(sizeof(char) * length);
rtnValue = (char *)malloc(sizeof(char) * (length+1));
if (!rtnValue)
return NULL;
if (!rtnValue)
return NULL;
strcpy(rtnValue, value);
strcpy(rtnValue, value);
if (!noData) {
length = length + len;
rtnValue = (char *)realloc(rtnValue, sizeof(char) * length);
strncat(rtnValue, buffer, len);
}
} else {
rtnValue = (char *)malloc(sizeof(char) * length);
if (!rtnValue)
return NULL;
strcpy(rtnValue, value);
if (!noData) {
length = length + lenShort;
rtnValue = (char *)realloc(rtnValue, sizeof(char) * length);
strncat(rtnValue, buffer, lenShort);
}
if (!noData) {
length = length + bufLen;
rtnValue = (char *)realloc(rtnValue, sizeof(char) * (length+1));
strncat(rtnValue, buffer, bufLen);
}
data = JRI_NewStringPlatform(env, rtnValue, length, NULL, 0);