| Issue 260: | String::____hxcpp_char_array_to_utf8_string with incoming zero-length string returns a string of length 1 | |
| 1 person starred this issue and may be notified of changes. | Back to list |
While working with the Utf8 class in Haxe for the cpp target, I discovered a problem in String::____hxcpp_char_array_to_utf8_string.
A quick Haxe code example of the problem:
var testUtf8 : String = Utf8.sub("test", 0, 0);
trace("testUtf8.length=" + Utf8.length(testUtf8));
Expected output:
testUtf8.length=0
Actual output:
testUtf8.length=1
In the function String::____hxcpp_char_array_to_utf8_string, if the incoming Array<int> has zero length, the access of inChars[0] on the first line of this function causes the array to grow to a length of 1 by the execution of ArrayBase.EnsureSize via Array's index operator.
Also, the return of String() in the case where inLen < 0 causes the resulting string in Haxe to be null.
This version of the function works with my application:
String __hxcpp_char_array_to_utf8_string(Array<int> &inChars,int inFirst, int inLen)
{
int len = inChars->length;
if (inFirst<0)
inFirst = 0;
if (inLen<0) inLen = len;
if (inFirst+inLen>len)
inLen = len-inFirst;
if (inLen<=0)
return HX_CSTRING("");
int *base = &inChars[0];
char *result = TConvertToUTF8(base+inFirst,&len);
return String(result,len);
}
Oct 29, 2013
Project Member
#1
gameh...@gmail.com
Status:
Fixed
|