summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-07-16 04:46:17 +0200
committerSven Gothel <[email protected]>2015-07-16 04:46:17 +0200
commita3701528aa4be01924c983ce74e2efeaba0e58bc (patch)
treea4a1bc1db592985e3cc762eb7bf8f87095a8a8d9 /src/java/com/jogamp
parent6ecc869eea932ac77dd6d4604eb205a8a659f83d (diff)
Bug 1166: Refine fix of JavaEmitter's JVMUtil_NewDirectByteBufferCopy (2)
Further refine code, see commit f6a5ac4473135bbc4bc1a5f537e060df45eb4824. - Perform a NULL check on Buffers.newDirectByteBuffer(..) result. - Only copy memory if capacity > 0, incl fetching direct buffer address
Diffstat (limited to 'src/java/com/jogamp')
-rw-r--r--src/java/com/jogamp/gluegen/JavaEmitter.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java
index f9a978d..02e56a4 100644
--- a/src/java/com/jogamp/gluegen/JavaEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaEmitter.java
@@ -2554,6 +2554,8 @@ public class JavaEmitter implements GlueEmitter {
"#define JINT_MAX_VALUE ((size_t)0x7fffffffU)\n"+
"static const char * sNewBufferImplNotCalled = \"initializeImpl() not called\";\n"+
"static const char * sNewBufferMAX_INT = \"capacity > MAX_INT\";\n"+
+ "static const char * sNewBufferNULL = \"New direct ByteBuffer is NULL\";\n"+
+ "\n"+
"static jobject JVMUtil_NewDirectByteBufferCopy(JNIEnv *env, void * source_address, size_t capacity) {\n"+
" jobject jbyteBuffer;\n"+
" void * byteBufferPtr;\n"+
@@ -2568,10 +2570,16 @@ public class JavaEmitter implements GlueEmitter {
" (*env)->FatalError(env, sNewBufferMAX_INT);\n"+
" return NULL;\n"+
" }\n"+
-
" jbyteBuffer = (*env)->CallStaticObjectMethod(env, clazzBuffers, cstrBuffersNew, (jint)capacity);\n"+
- " byteBufferPtr = (*env)->GetDirectBufferAddress(env, jbyteBuffer);\n"+
- " memcpy(byteBufferPtr, source_address, capacity);\n"+
+ " if( NULL == jbyteBuffer ) {\n"+
+ " fprintf(stderr, \"%s %s: size %lu\\n\", sFatalError, sNewBufferNULL, (unsigned long)capacity);\n"+
+ " (*env)->FatalError(env, sNewBufferNULL);\n"+
+ " return NULL;\n"+
+ " }\n"+
+ " if( 0 < capacity ) {\n"+
+ " byteBufferPtr = (*env)->GetDirectBufferAddress(env, jbyteBuffer);\n"+
+ " memcpy(byteBufferPtr, source_address, capacity);\n"+
+ " }\n"+
" return jbyteBuffer;\n"+
"}\n"+
"\n";