From e803640027323b9bacc29bf3d11ee83f4464bd0b Mon Sep 17 00:00:00 2001 From: "chaos.proton@gmail.com" Date: Wed, 2 Nov 2011 08:58:34 +0000 Subject: [PATCH] avoid divided by zero error The old code only checks touch->max_x > touch->min_x but not touch->max_x == touch->min_x. Thus may lead to divided by zero error. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1782 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- bsp/stm32f10x/touch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsp/stm32f10x/touch.c b/bsp/stm32f10x/touch.c index e41d840fde..397f94a2f4 100644 --- a/bsp/stm32f10x/touch.c +++ b/bsp/stm32f10x/touch.c @@ -158,7 +158,7 @@ static void rtgui_touch_calculate() { touch->x = (touch->x - touch->min_x) * X_WIDTH/(touch->max_x - touch->min_x); } - else + else if (touch->max_x < touch->min_x) { touch->x = (touch->min_x - touch->x) * X_WIDTH/(touch->min_x - touch->max_x); } @@ -167,7 +167,7 @@ static void rtgui_touch_calculate() { touch->y = (touch->y - touch->min_y) * Y_WIDTH /(touch->max_y - touch->min_y); } - else + else if (touch->max_y < touch->min_y) { touch->y = (touch->min_y - touch->y) * Y_WIDTH /(touch->min_y - touch->max_y); }