mirror of
https://github.com/corda/corda.git
synced 2025-01-03 19:54:13 +00:00
fix makeByteArray and makeString for strings longer than 256 characters
This commit is contained in:
parent
5a5d2a8dd2
commit
6fceca940f
@ -3048,17 +3048,32 @@ popResources(Thread* t)
|
||||
}
|
||||
|
||||
object
|
||||
makeByteArray(Thread* t, const char* format, va_list a)
|
||||
makeByteArray(Thread* t, const char* format, va_list a, int size)
|
||||
{
|
||||
THREAD_RUNTIME_ARRAY(t, char, buffer, size);
|
||||
|
||||
int r = vm::vsnprintf(RUNTIME_ARRAY_BODY(buffer), size - 1, format, a);
|
||||
if (r >= 0 and r < size - 1) {
|
||||
object s = makeByteArray(t, strlen(RUNTIME_ARRAY_BODY(buffer)) + 1);
|
||||
memcpy(&byteArrayBody(t, s, 0), RUNTIME_ARRAY_BODY(buffer),
|
||||
byteArrayLength(t, s));
|
||||
return s;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
object
|
||||
makeByteArray(Thread* t, const char* format, ...)
|
||||
{
|
||||
int size = 256;
|
||||
while (true) {
|
||||
THREAD_RUNTIME_ARRAY(t, char, buffer, size);
|
||||
|
||||
int r = vm::vsnprintf(RUNTIME_ARRAY_BODY(buffer), size - 1, format, a);
|
||||
if (r >= 0 and r < size - 1) {
|
||||
object s = makeByteArray(t, strlen(RUNTIME_ARRAY_BODY(buffer)) + 1);
|
||||
memcpy(&byteArrayBody(t, s, 0), RUNTIME_ARRAY_BODY(buffer),
|
||||
byteArrayLength(t, s));
|
||||
va_list a;
|
||||
va_start(a, format);
|
||||
object s = makeByteArray(t, format, a, size);
|
||||
va_end(a);
|
||||
|
||||
if (s) {
|
||||
return s;
|
||||
} else {
|
||||
size *= 2;
|
||||
@ -3066,26 +3081,22 @@ makeByteArray(Thread* t, const char* format, va_list a)
|
||||
}
|
||||
}
|
||||
|
||||
object
|
||||
makeByteArray(Thread* t, const char* format, ...)
|
||||
{
|
||||
va_list a;
|
||||
va_start(a, format);
|
||||
object s = makeByteArray(t, format, a);
|
||||
va_end(a);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
object
|
||||
makeString(Thread* t, const char* format, ...)
|
||||
{
|
||||
va_list a;
|
||||
va_start(a, format);
|
||||
object s = makeByteArray(t, format, a);
|
||||
va_end(a);
|
||||
int size = 256;
|
||||
while (true) {
|
||||
va_list a;
|
||||
va_start(a, format);
|
||||
object s = makeByteArray(t, format, a, size);
|
||||
va_end(a);
|
||||
|
||||
return t->m->classpath->makeString(t, s, 0, byteArrayLength(t, s) - 1);
|
||||
if (s) {
|
||||
return t->m->classpath->makeString(t, s, 0, byteArrayLength(t, s) - 1);
|
||||
} else {
|
||||
size *= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -2214,7 +2214,7 @@ make(Thread* t, object class_)
|
||||
}
|
||||
|
||||
object
|
||||
makeByteArray(Thread* t, const char* format, va_list a);
|
||||
makeByteArray(Thread* t, const char* format, va_list a, int size);
|
||||
|
||||
object
|
||||
makeByteArray(Thread* t, const char* format, ...);
|
||||
|
Loading…
Reference in New Issue
Block a user