changeset 871:9cc9e2462d9a

Avoid FPE with Linux 2.6
author Sam Lantinga <slouken@libsdl.org>
date Fri, 05 Mar 2004 15:09:18 +0000
parents 95f22f17e44a
children e7be95d758e8
files src/joystick/linux/SDL_sysjoystick.c
diffstat 1 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/joystick/linux/SDL_sysjoystick.c	Thu Mar 04 05:41:57 2004 +0000
+++ b/src/joystick/linux/SDL_sysjoystick.c	Fri Mar 05 15:09:18 2004 +0000
@@ -383,7 +383,7 @@
 
 static SDL_bool EV_ConfigJoystick(SDL_Joystick *joystick, int fd)
 {
-	int i;
+	int i, t;
 	unsigned long keybit[40];
 	unsigned long absbit[40];
 	unsigned long relbit[40];
@@ -436,12 +436,18 @@
 				    joystick->hwdata->abs_correct[i].used = 0;
 				} else {
 				    joystick->hwdata->abs_correct[i].used = 1;
-				    joystick->hwdata->abs_correct[i].coef[0] =
-					(values[2] + values[1]) / 2 - values[4];
-				    joystick->hwdata->abs_correct[i].coef[1] =
-					(values[2] + values[1]) / 2 + values[4];
-				    joystick->hwdata->abs_correct[i].coef[2] =
-					(1 << 29) / ((values[2] - values[1]) / 2 - 2 * values[4]);
+				    t = (2 - values[4]);
+				    if ( t != 0 ) {
+				        joystick->hwdata->abs_correct[i].coef[0] = (values[2] + values[1]) / t;
+				    }
+				    t = (2 + values[4]);
+				    if ( t != 0 ) {
+				        joystick->hwdata->abs_correct[i].coef[1] = (values[2] + values[1]) / t;
+				    }
+				    t = ((values[2] - values[1]) / 2 - 2 * values[4]);
+				    if ( t != 0 ) {
+					joystick->hwdata->abs_correct[i].coef[2] = (1 << 29) / t;
+				    }
 				}
 				++joystick->naxes;
 			}