author | sandman <sandman> | 2002-10-31 03:11:34 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-10-31 03:11:34 (UTC) |
commit | d4c2baf3d4998001462ac1be04523b216da02500 (patch) (unidiff) | |
tree | d017a5598492e631988786fb50d45cfde34c9aec | |
parent | d9d6cc6b3a537439affc8095dedd046c86f09d9e (diff) | |
download | opie-d4c2baf3d4998001462ac1be04523b216da02500.zip opie-d4c2baf3d4998001462ac1be04523b216da02500.tar.gz opie-d4c2baf3d4998001462ac1be04523b216da02500.tar.bz2 |
added a sanity check to avoid a division by 0 in case the config file
contains bad data
-rw-r--r-- | core/launcher/screensaver.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp index 45da9ed..088ed19 100644 --- a/core/launcher/screensaver.cpp +++ b/core/launcher/screensaver.cpp | |||
@@ -187,8 +187,10 @@ void OpieScreenSaver::setBacklight ( int bright ) | |||
187 | for ( uint i = 0; i < LS_Count; i++ ) { | 187 | for ( uint i = 0; i < LS_Count; i++ ) { |
188 | if ( i < sl. count ( )) | 188 | if ( i < sl. count ( )) |
189 | m_sensordata [i] = sl [i]. toInt ( ); | 189 | m_sensordata [i] = sl [i]. toInt ( ); |
190 | } | 190 | } |
191 | if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE | ||
192 | m_sensordata [LS_Steps] = 2; | ||
191 | 193 | ||
192 | timerEvent ( 0 ); | 194 | timerEvent ( 0 ); |
193 | startTimer ( m_sensordata [LS_Interval] ); | 195 | startTimer ( m_sensordata [LS_Interval] ); |
194 | } | 196 | } |
@@ -232,9 +234,9 @@ void OpieScreenSaver::timerEvent ( QTimerEvent * ) | |||
232 | else { | 234 | else { |
233 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; | 235 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; |
234 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; | 236 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; |
235 | 237 | ||
236 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; | 238 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 |
237 | 239 | ||
238 | m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); | 240 | m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); |
239 | } | 241 | } |
240 | if ( !m_backlight_sensor ) | 242 | if ( !m_backlight_sensor ) |