-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
UTFStringRef.set() throws IllegalArgumentException #159
Comments
Due to the incompatibility of JNR with Android, I'm going to have to stop using JNR and write my bindings directly with JNI. I should have probably checked that before starting to write my bindings. Anyways, the immediate solution I came up with was to drop back to |
Thanks for the workaround info, and I'm sorry we did not see this issue! Did you ever figure out what was causing the problem in JNR? |
No worries! I'm not really fantastic about keeping up with my own repos haha If I remember correctly changing length() to value.length() would have fixed it. I ended up having to focus on other stuff and now work elsewhere, so I can't really go back and try running it again with a patched version. If you want to create a reproducible example, create a struct with a string field and try to set it on the Java side before passing that struct over to the native side. At a higher level, we were better off re-implementing the protocol we were trying to port with Android's socket library for better integration into the API (handler/looper stuff) so I doubt whoever is continuing my work would be working with the same bindings I wrote. |
I am still able to reproduce this issue - and I agree with @Robmaister's assessment:
This looks like it would resolve the issue. |
…row an IllegalArgumentException. Fixes jnr#159.
This is currently broken on the JVM due to jnr/jnr-ffi#159.
Thanks for waking this one up with a fix! |
We need jnr/jnr-ffi#159 to be fixed first.
I'm trying to wrap a library that has some structs that expose bare
char*
strings. When I try to set one of these values using UTFStringRef.set, I get the following exception:I can include some code, but unless I'm mistaken, there's a relatively straightforward bug here:
https://github.com/jnr/jnr-ffi/blob/master/src/main/java/jnr/ffi/Struct.java#L2364
I believe that both instances of
length()
here were intended to bevalue.length()
instead. By default, the constructor sets the value oflength()
toInteger.MAX_VALUE
, and it would make sense to allocate a buffer of the same size as the incoming string.Also along the same lines, does
String.length()
in Java include the size of a null terminator? Should it perhaps be(value.length() + 1) * 4
?If I'm completely off track here let me know and I'll include some code with what I'm trying to accomplish
The text was updated successfully, but these errors were encountered: