diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-12-07 14:29:05 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-12-07 14:29:05 -0800 |
commit | 4dc3061aa58b25bd01c215777531a8801b151e93 (patch) | |
tree | 435eadbe21c48d1078f8aade08f7c43c0493e3bd /planner.c | |
parent | 4623d7098bc7c5c7c6e90d916359e3a578fb91dd (diff) | |
download | subsurface-4dc3061aa58b25bd01c215777531a8801b151e93.tar.gz |
Use AL80 as default if no default cylinder is set
Otherwise the user could get uninitialized values for newly created
cylinders.
Fixes #345
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r-- | planner.c | 37 |
1 files changed, 21 insertions, 16 deletions
@@ -172,22 +172,27 @@ static int time_at_last_depth(struct dive *dive, int o2, int he, unsigned int ne void fill_default_cylinder(cylinder_t *cyl) { - if (prefs.default_cylinder) { - struct tank_info_t *ti = tank_info; - while (ti->name != NULL) { - if (strcmp(ti->name, prefs.default_cylinder) == 0) { - cyl->type.description = strdup(prefs.default_cylinder); - if (ti->ml) { - cyl->type.size.mliter = ti->ml; - cyl->type.workingpressure.mbar = ti->bar * 1000; - } else { - cyl->type.workingpressure.mbar = psi_to_mbar(ti->psi); - cyl->type.size.mliter = cuft_to_l(ti->cuft) * 1000 / bar_to_atm(psi_to_bar(ti->psi)); - } - return; - } - ti++; - } + const char *cyl_name = prefs.default_cylinder != NULL ? prefs.default_cylinder : "AL80"; + struct tank_info_t *ti = tank_info; + struct tank_info_t *al80 = NULL; + + while (ti->name != NULL) { + if (strcmp(ti->name, cyl_name) == 0) + break; + if (strcmp(ti->name, "AL80") == 0) + al80 = ti; + ti++; + } + if (ti->name == NULL) + ti = al80; + cyl->type.description = strdup(ti->name); + if (ti->ml) { + cyl->type.size.mliter = ti->ml; + cyl->type.workingpressure.mbar = ti->bar * 1000; + } else { + cyl->type.workingpressure.mbar = psi_to_mbar(ti->psi); + if (ti->psi) + cyl->type.size.mliter = cuft_to_l(ti->cuft) * 1000 / bar_to_atm(psi_to_bar(ti->psi)); } } |