Depth validation in planner
Henrik Brautaset Aronsen
subsurface at henrik.synth.no
Wed Feb 13 04:05:20 PST 2013
Here's a fix. Does it look OK?
diff --git a/planner.c b/planner.c
index 6ae8333..6b08143 100644
--- a/planner.c
+++ b/planner.c
@@ -864,6 +864,8 @@ static int validate_depth(const char *text, int *mm_p)
} else {
depth *= 100;
}
+ if (depth > 300000) depth = 300000;
+
*mm_p = depth;
return 1;
}
@@ -1017,11 +1019,14 @@ static void gas_changed_cb(GtkWidget *combo,
gpointer data)
static gboolean depth_focus_out_cb(GtkWidget *entry, GdkEvent *event,
gpointer data)
{
const char *depthtext;
+ char updatedtext[10];
int depth;
int idx = data - NULL;
depthtext = gtk_entry_get_text(GTK_ENTRY(entry));
if (validate_depth(depthtext, &depth)) {
+ snprintf(updatedtext, sizeof(updatedtext), "%d",
depth/1000);
+ gtk_entry_set_text(GTK_ENTRY(entry), updatedtext);
add_depth_to_nth_dp(&diveplan, idx, depth);
show_planned_dive();
} else {
If so:
Signed-off-by: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
Henrik
On Wed, Feb 13, 2013 at 11:59 AM, Henrik Brautaset Aronsen <
subsurface at henrik.synth.no> wrote:
> On Wed, Feb 13, 2013 at 11:56 AM, Robert C. Helling <helling at lmu.de>wrote:
>
>> On Wed, 13 Feb 2013, Sergey Starosek wrote:
>>
>> Hi,
>>> During testing I've accidentally entered depth of 1000m with 1min
>>> duration for the first segment. At this point application
>>> stops responding for a long time and consumes 100% CPU on one of the
>>> cores. Every focus change makes it even worse.
>>>
>>
>> I think, it's calculating a very long deco. You can see it for a 400m
>> dive: For me it takes several seconds to come up with a plan to come out of
>> the water (which asks for about 3000 minutes of deco). So for your 1km
>> dive, we might have to wait longer than MAX_INT seconds.
>>
>
>
> We should still have a cutoff. Noone is seriously going to plan a dive
> deeper than ~300m.
>
> H
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20130213/b8f49d95/attachment.html>
More information about the subsurface
mailing list