mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Fix divide-by-zero bug in statistics.c
GET_LOCAL_SAC did not check if the two entries had different time stamps and could therefore cause a divide-by-zero. x86 doesn't fault on that - it's still wrong. This now calls a function that does proper checking of all the values involved in the calculation. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
49b4f7c4ac
commit
bc5f82990d
1 changed files with 25 additions and 5 deletions
30
profile.c
30
profile.c
|
@ -1010,12 +1010,32 @@ static void set_sac_color(struct graphics_context *gc, int sac, int avg_sac)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double get_local_sac(struct plot_data *entry1, struct plot_data *entry2, struct dive *dive)
|
||||||
|
{
|
||||||
|
int index = entry1->cylinderindex;
|
||||||
|
int delta_time = entry2->sec - entry1->sec;
|
||||||
|
double depth;
|
||||||
|
long delta_pressure = GET_PRESSURE(entry1) - GET_PRESSURE(entry2);
|
||||||
|
long mliter;
|
||||||
|
|
||||||
|
if (entry2->cylinderindex != index)
|
||||||
|
return 0;
|
||||||
|
if (delta_pressure <= 0)
|
||||||
|
return 0;
|
||||||
|
if (delta_time <= 0)
|
||||||
|
return 0;
|
||||||
|
depth = (entry1->depth + entry2->depth) / 2.0;
|
||||||
|
|
||||||
|
mliter = dive->cylinder[index].type.size.mliter;
|
||||||
|
|
||||||
|
return delta_pressure * mliter /
|
||||||
|
(delta_time / 60.0) /
|
||||||
|
depth_to_mbar(depth, dive);
|
||||||
|
}
|
||||||
|
|
||||||
/* calculate the current SAC in ml/min and convert to int */
|
/* calculate the current SAC in ml/min and convert to int */
|
||||||
#define GET_LOCAL_SAC(_entry1, _entry2, _dive) (int) \
|
#define GET_LOCAL_SAC(_entry1, _entry2, _dive) \
|
||||||
((GET_PRESSURE((_entry1)) - GET_PRESSURE((_entry2))) * \
|
(int) get_local_sac(_entry1, _entry2, _dive)
|
||||||
(_dive)->cylinder[(_entry1)->cylinderindex].type.size.mliter / \
|
|
||||||
(((_entry2)->sec - (_entry1)->sec) / 60.0) / \
|
|
||||||
depth_to_mbar(((_entry1)->depth + (_entry2)->depth) / 2.0, (_dive)))
|
|
||||||
|
|
||||||
#define SAC_WINDOW 45 /* sliding window in seconds for current SAC calculation */
|
#define SAC_WINDOW 45 /* sliding window in seconds for current SAC calculation */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue