8178274: Java_sun_lwawt_macosx_NSEvent_nsToJavaKeyInfo() overreads jchar variable
authorasmotrak
Fri, 22 Sep 2017 18:57:05 -0700
changeset 47370 099d4d178224
parent 47369 a28c513d1c4e
child 47371 9318793bdc36
8178274: Java_sun_lwawt_macosx_NSEvent_nsToJavaKeyInfo() overreads jchar variable Reviewed-by: ssadetsky
src/java.desktop/macosx/native/libawt_lwawt/awt/AWTEvent.m
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTEvent.m	Fri Sep 22 18:20:18 2017 -0700
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTEvent.m	Fri Sep 22 18:57:05 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -387,7 +387,7 @@
     if (nsChar == 0 && spaceKeyTyped == YES) {
         return java_awt_event_KeyEvent_VK_SPACE;
     }
-	
+
     // otherwise return character unchanged
     return nsChar;
 }
@@ -439,7 +439,8 @@
 static void
 NsCharToJavaVirtualKeyCode(unichar ch, BOOL isDeadChar,
                            NSUInteger flags, unsigned short key,
-                           jint *keyCode, jint *keyLocation, BOOL *postsTyped, unichar *deadChar)
+                           jint *keyCode, jint *keyLocation, BOOL *postsTyped,
+                           unichar *deadChar)
 {
     static size_t size = sizeof(keyTable) / sizeof(struct _key);
     NSInteger offset;
@@ -562,10 +563,10 @@
 {
     jint javaModifiers = 0;
     const struct _nsKeyToJavaModifier* cur;
-	
+
     for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
         if ((cur->nsMask & nsFlags) != 0) {
-			
+
             if (cur->nsMask == NSAlternateKeyMask) {
                 if (leftAltKeyPressed == YES) {
                     javaModifiers |= isExtMods? cur->javaExtMask : cur->javaMask;
@@ -707,16 +708,17 @@
 
     jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
     jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
-    jchar testDeadChar = 0;
+    jint testDeadChar = 0;
 
     NsCharToJavaVirtualKeyCode((unichar)testChar, isDeadChar,
                                (NSUInteger)modifierFlags, (unsigned short)keyCode,
-                               &jkeyCode, &jkeyLocation, &postsTyped, &testDeadChar);
+                               &jkeyCode, &jkeyLocation, &postsTyped,
+                               (unichar *) &testDeadChar);
 
-    // out = [jkeyCode, jkeyLocation];
+    // out = [jkeyCode, jkeyLocation, deadChar];
     (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
     (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
-    (*env)->SetIntArrayRegion(env, outData, 2, 1, (jint *)&testDeadChar);
+    (*env)->SetIntArrayRegion(env, outData, 2, 1, &testDeadChar);
 
     (*env)->ReleaseIntArrayElements(env, inData, data, 0);