diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-01-07 13:50:53 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-07 13:50:53 -0800 |
commit | e47e37e5a6eb5e4d1386d4b7f02d9997e22b39f1 (patch) | |
tree | 82747e29017b69e7a2db1d0f4f58a9ea25c4d674 /deco.c | |
parent | e6afd055d870d677dd0edf243bc2f42ab0a2fbd1 (diff) | |
download | subsurface-e47e37e5a6eb5e4d1386d4b7f02d9997e22b39f1.tar.gz |
Add bailout code to prevent infinite loop in deco calculation
This appears to happen if we have impossible dive sequences in the
dive_list (i.e., merging XML files from two different divers with
overlapping trips).
We need to fix the underlying cause for this issue (i.e., only pick the
'right' dives to calculate the residual tissue saturation), but at least
this code prevents the hang in an infinite loop.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'deco.c')
-rw-r--r-- | deco.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -273,6 +273,7 @@ unsigned int deco_allowed_depth(double tissues_tolerance, double surface_pressur double new_gradient_factor; double pressure_delta = tissues_tolerance - surface_pressure; struct dive_data mydata; + int bail = 1000; if (pressure_delta > 0) { if (!smooth) { @@ -291,6 +292,12 @@ unsigned int deco_allowed_depth(double tissues_tolerance, double surface_pressur below_gradient_limit = (new_gradient_factor < actual_gradient_limit(&mydata)); while(!below_gradient_limit) { + /* we run into bugs where this turns into an infinite loop; so add + * some bailout code that prints a warning but prevents the code from hanging */ + if (--bail == 0) { + printf("WARNING!!!\n==========\nThe deco_allowed_depth() loop appears to hang.\nBailing out.\n"); + break; + } if (!smooth) mydata.pressure += PRESSURE_CHANGE_3M; else |