Skip to content

direct-mapping with type-mapper return-types crashes #317

@marco2357

Description

@marco2357

If OwnString is handled in a type mapper (instead of being NativeMapped), calling this strstr() method will crash due to the return type (arguments work, return types not):

class Test {
   static {
      Native.register(NativeLibrary.getInstance(C_LIBRARY_NAME, mapWithOwnTypeMapper));
   }

   private static native OwnString strstr(OwnString haystack, OwnString needle);
}

Here the fix (the result is created but never used/assigned):

diff --git a/native/dispatch.c b/native/dispatch.c
index 71fd083..fc17dd7 100644
--- a/native/dispatch.c
+++ b/native/dispatch.c
@@ -1149,6 +1149,9 @@
       if (type->type != FFI_TYPE_POINTER) {
         extract_value(env, obj, result, type->size, JNI_TRUE);
       }
+      else {
+        *(jobject*)result = obj;
+      }
     }
   }
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions