fix makeByteArray and makeString for strings longer than 256 characters

This commit is contained in:
Joel Dice 2012-02-29 11:49:13 -07:00
parent 5a5d2a8dd2
commit 6fceca940f
2 changed files with 36 additions and 25 deletions

View File

@ -3048,10 +3048,8 @@ popResources(Thread* t)
} }
object object
makeByteArray(Thread* t, const char* format, va_list a) makeByteArray(Thread* t, const char* format, va_list a, int size)
{ {
int size = 256;
while (true) {
THREAD_RUNTIME_ARRAY(t, char, buffer, size); THREAD_RUNTIME_ARRAY(t, char, buffer, size);
int r = vm::vsnprintf(RUNTIME_ARRAY_BODY(buffer), size - 1, format, a); int r = vm::vsnprintf(RUNTIME_ARRAY_BODY(buffer), size - 1, format, a);
@ -3061,31 +3059,44 @@ makeByteArray(Thread* t, const char* format, va_list a)
byteArrayLength(t, s)); byteArrayLength(t, s));
return s; return s;
} else { } else {
size *= 2; return 0;
}
} }
} }
object object
makeByteArray(Thread* t, const char* format, ...) makeByteArray(Thread* t, const char* format, ...)
{ {
int size = 256;
while (true) {
va_list a; va_list a;
va_start(a, format); va_start(a, format);
object s = makeByteArray(t, format, a); object s = makeByteArray(t, format, a, size);
va_end(a); va_end(a);
if (s) {
return s; return s;
} else {
size *= 2;
}
}
} }
object object
makeString(Thread* t, const char* format, ...) makeString(Thread* t, const char* format, ...)
{ {
int size = 256;
while (true) {
va_list a; va_list a;
va_start(a, format); va_start(a, format);
object s = makeByteArray(t, format, a); object s = makeByteArray(t, format, a, size);
va_end(a); va_end(a);
if (s) {
return t->m->classpath->makeString(t, s, 0, byteArrayLength(t, s) - 1); return t->m->classpath->makeString(t, s, 0, byteArrayLength(t, s) - 1);
} else {
size *= 2;
}
}
} }
int int

View File

@ -2214,7 +2214,7 @@ make(Thread* t, object class_)
} }
object object
makeByteArray(Thread* t, const char* format, va_list a); makeByteArray(Thread* t, const char* format, va_list a, int size);
object object
makeByteArray(Thread* t, const char* format, ...); makeByteArray(Thread* t, const char* format, ...);