fixes for issues 25 and 26

Sigsgv with logitec USB keyboard with volume controls and mouse wheel

when valid event device list in /dev/input/event* has invalid devices in the middle of the sequence, a sigsegv is seen
This commit is contained in:
endolf 2004-04-21 09:48:55 +00:00
parent 54ecf9687a
commit 2dc9aae5e2
7 changed files with 32 additions and 26 deletions

View file

@ -44,8 +44,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

View file

@ -25,11 +25,7 @@
*/
package net.java.games.input;
import net.java.games.input.AbstractController;
import net.java.games.input.Axis;
import net.java.games.input.Controller;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Represents a device that is not a keyboard or mouse.
@ -189,13 +185,15 @@ public class LinuxDevice extends AbstractController {
*/
private void createButtons(int numButtons) {
int supportedButtons[] = new int[numButtons];
getSupportedButtons(supportedButtons);
buttons = new LinuxAxis[numButtons];
for(int i=0;i<numButtons;i++) {
buttons[i] = createButton(i, supportedButtons[i]);
//axesArray.add(buttons[i]);
}
int supportedButtons[] = new int[numButtons];
buttons = new LinuxAxis[numButtons];
if(numButtons>0) {
getSupportedButtons(supportedButtons);
for(int i=0;i<numButtons;i++) {
buttons[i] = createButton(i, supportedButtons[i]);
//axesArray.add(buttons[i]);
}
}
}
/** Create the relative axes for the device
@ -567,6 +565,9 @@ public class LinuxDevice extends AbstractController {
* @param supportedButtons Array to populate
*/
private void getSupportedButtons(int supportedButtons[]) {
if(supportedButtons.length==0) {
return;
}
getNativeSupportedButtons(nativeID, supportedButtons);
}

View file

@ -25,10 +25,6 @@
*/
package net.java.games.input;
import java.util.ArrayList;
import java.util.Iterator;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
import net.java.games.util.plugins.Plugin;
/** Environment plugin for linux

View file

@ -34,6 +34,8 @@
#include <malloc.h>
#include <errno.h>
#include "logger.h"
EventDevice::EventDevice(char *deviceFileName) {
char tempName[Device::MAX_NAME_LENGTH-1] = "Unknown";
int i;
@ -57,6 +59,8 @@ EventDevice::EventDevice(char *deviceFileName) {
name = (char *)malloc(namelength+1);
strncpy(name,tempName, namelength+1);
LOG_TRACE("Device name for device file %s is %s\n", deviceFileName, name);
uint8_t evtype_bitmask[EV_MAX/8 + 1];
memset(evtype_bitmask, 0, sizeof(evtype_bitmask));
@ -213,6 +217,7 @@ int EventDevice::getNumberButtons(){
}
const char *EventDevice::getName(){
LOG_TRACE("EventDevice::getName()\n");
return name;
}
@ -336,7 +341,7 @@ int EventDevice::poll(){
// reveiced for things like numlock led change
break;
default:
fprintf(stderr, "Received event of type 0x%02X from %s, which I wasn't expecting, please report it to jinput@computerbooth.com\n", events[i].type, name);
fprintf(stderr, "Received event of type 0x%02X from %s, which I wasn't expecting, please report it to jinput forum at www.javagaming.org\n", events[i].type, name);
}
}
return dataChanged;

View file

@ -42,13 +42,13 @@
<target name="compileNativeEventLib" depends="init">
<exec dir="." executable="g++" os="Linux">
<arg line="--shared -o libeventInterface.so eventInterface.cpp EventDevice.cpp"/>
<arg line="--shared -DLOGTRACE -o libeventInterface.so eventInterface.cpp EventDevice.cpp"/>
</exec>
</target>
<target name="compileNativeJinputLib" depends="init">
<exec dir="." executable="g++" os="Linux">
<arg line="-I${java.home}/include -I${java.home}/include/linux --shared -o libjinput.so jinput.cpp eventInterface.cpp EventDevice.cpp joystickInterface.cpp JoystickDevice.cpp MixedDevice.cpp"/>
<arg line="-I${java.home}/include -I${java.home}/include/linux --shared -DLOGTRACE -o libjinput.so jinput.cpp eventInterface.cpp EventDevice.cpp joystickInterface.cpp JoystickDevice.cpp MixedDevice.cpp"/>
</exec>
</target>
</project>

View file

@ -36,6 +36,8 @@
#include "Device.h"
#include "EventDevice.h"
#include "logger.h"
int evNumDevices;
int eventInterfaceVersion;
Device **evDeviceList;
@ -103,6 +105,8 @@ int evInit() {
if(tempDevice->isValidDevice()==1) {
tempDeviceList[i] = tempDevice;
evNumDevices++;
} else {
tempDeviceList[i] = NULL;
}
}
@ -115,7 +119,7 @@ int evInit() {
evTempDeviceCount++;
}
evDeviceList[i] = tempDeviceList[evTempDeviceCount];
//printf("Copied device %d to %d\n", evTempDeviceCount, i);
LOG_TRACE("Copied temp event device %d to event device %d\n", evTempDeviceCount, i);
evTempDeviceCount++;
}

View file

@ -131,7 +131,9 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_init
JNIEXPORT jstring JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getDeviceName
(JNIEnv *env, jobject, jint deviceID) {
LOG_TRACE("Gettign device name for jinput device %d\n", deviceID);
LOG_TRACE("Gettign device name for jinput device %d.\n", deviceID);
LOG_TRACE("jinput device %d is %d\n", deviceID, jinputDeviceList[deviceID]);
LOG_TRACE("Gettign device name for jinput device %d, (%s)\n", deviceID, jinputDeviceList[deviceID]->getName());
return env->NewStringUTF(jinputDeviceList[deviceID]->getName());
}
@ -143,7 +145,7 @@ JNIEXPORT jstring JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getDe
JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getNumAbsAxes
(JNIEnv *env, jobject, jint deviceID) {
LOG_TRACE("Gettign number of absolute axes for jinput device %d\n", deviceID);
LOG_TRACE("Gettign number of absolute axes for jinput device %d (%d)\n", deviceID, jinputDeviceList[deviceID]->getNumberAbsAxes());
return jinputDeviceList[deviceID]->getNumberAbsAxes();
}
@ -155,7 +157,7 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getNumAb
JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getNumRelAxes
(JNIEnv *env, jobject, jint deviceID) {
LOG_TRACE("Gettign number of relative axes for jinput device %d\n", deviceID);
LOG_TRACE("Gettign number of relative axes for jinput device %d (%d)\n", deviceID, jinputDeviceList[deviceID]->getNumberRelAxes());
return jinputDeviceList[deviceID]->getNumberRelAxes();
}
@ -167,7 +169,7 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getNumRe
JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getNumButtons
(JNIEnv *, jobject, jint deviceID) {
LOG_TRACE("Gettign number of buttons for jinput device %d\n", deviceID);
LOG_TRACE("Gettign number of buttons for jinput device %d (%d)\n", deviceID, jinputDeviceList[deviceID]->getNumberButtons());
return jinputDeviceList[deviceID]->getNumberButtons();
}
@ -224,7 +226,7 @@ JNIEXPORT void JNICALL Java_net_java_games_input_LinuxDevice_getNativeSupportedB
jint *buttonDataElements = env->GetIntArrayElements(buttonData, 0);
LOG_TRACE("Getting suported buttons for jinput device %d\n", deviceID);
LOG_TRACE("Getting supported buttons for jinput device %d\n", deviceID);
jinputDeviceList[deviceID]->getSupportedButtons(buttonDataElements);
env->ReleaseIntArrayElements(buttonData, buttonDataElements, 0);