Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JNI NewString crashes when char length is zero #13

Closed
marcprux opened this issue Oct 2, 2012 · 1 comment
Closed

JNI NewString crashes when char length is zero #13

marcprux opened this issue Oct 2, 2012 · 1 comment

Comments

@marcprux
Copy link

marcprux commented Oct 2, 2012

The following code will crash in Avian:

jstring javaStr = (*jni)->NewString(jni, (jchar *)buffer, 0);

This patch will fix it:

diff --git a/VM/avian/jnienv.cpp b/VM/avian/jnienv.cpp
index 9e1d7e9..52da955 100644
--- a/VM/avian/jnienv.cpp
+++ b/VM/avian/jnienv.cpp
@@ -241,9 +241,8 @@ newString(Thread* t, uintptr_t* arguments)
   const jchar* chars = reinterpret_cast<const jchar*>(arguments[0]);
   jsize size = arguments[1];

-  object a = 0;
+  object a = makeCharArray(t, size);
   if (size) {
-    a = makeCharArray(t, size);
     memcpy(&charArrayBody(t, a, 0), chars, size * sizeof(jchar));
   }
@dicej
Copy link
Member

dicej commented Oct 3, 2012

Thanks; I've applied your patch:

ab5ec51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants