From 721e99406c0b086ed79dac5c457cd4e9f4424de5 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 30 Apr 2018 18:32:58 +0200 Subject: [PATCH] internal/mobileinit,bind/java,app: don't treat jobject as a pointer On Android, the JNI jobject type doesn't always contain a pointer. Treating a non-pointer as a pointer can crash the runtime. Use the more appropriate type uintptr instead. Change-Id: I2b2049918d60226c4d23d6df0b10e68248d54bc2 Reviewed-on: https://go-review.googlesource.com/110256 Reviewed-by: Brad Fitzpatrick --- app/android.go | 2 +- bind/java/context_android.go | 2 +- internal/mobileinit/ctx_android.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/android.go b/app/android.go index dff66c9..883a93c 100644 --- a/app/android.go +++ b/app/android.go @@ -68,7 +68,7 @@ import ( //export setCurrentContext func setCurrentContext(vm *C.JavaVM, ctx C.jobject) { - mobileinit.SetCurrentContext(unsafe.Pointer(vm), unsafe.Pointer(ctx)) + mobileinit.SetCurrentContext(unsafe.Pointer(vm), uintptr(ctx)) } //export callMain diff --git a/bind/java/context_android.go b/bind/java/context_android.go index cf41109..dc44431 100644 --- a/bind/java/context_android.go +++ b/bind/java/context_android.go @@ -17,5 +17,5 @@ import ( //export setContext func setContext(vm *C.JavaVM, ctx C.jobject) { - mobileinit.SetCurrentContext(unsafe.Pointer(vm), unsafe.Pointer(ctx)) + mobileinit.SetCurrentContext(unsafe.Pointer(vm), uintptr(ctx)) } diff --git a/internal/mobileinit/ctx_android.go b/internal/mobileinit/ctx_android.go index 559f918..e0dc166 100644 --- a/internal/mobileinit/ctx_android.go +++ b/internal/mobileinit/ctx_android.go @@ -78,7 +78,7 @@ import ( // SetCurrentContext populates the global Context object with the specified // current JavaVM instance (vm) and android.context.Context object (ctx). // The android.context.Context object must be a global reference. -func SetCurrentContext(vm, ctx unsafe.Pointer) { +func SetCurrentContext(vm unsafe.Pointer, ctx uintptr) { C.current_vm = (*C.JavaVM)(vm) C.current_ctx = (C.jobject)(ctx) }