Fix cylinder printout information

If we print out the pressure difference (because we do not have a cylinder
size), we didn't initialize the precision. We should print out pressures
without decimals.

The attached patch fixes that, and also avoids a NULL pointer printout
(which on Linux will just print out "(null)") if there is no cylinder
type descriptor string. It also cleans things up a bit and uses the
"cyl" pointer instead of repeating the "dive->cylinder[n]" thing.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2013-01-03 13:01:49 -08:00 committed by Dirk Hohndel
parent 3c5ebfe036
commit e5e2fb2038

12
print.c
View file

@ -229,7 +229,7 @@ static void print_tanks (struct dive *dive, cairo_t *cr, int maxwidth, int maxhe
counter = 0;
while ( n < tank_count && n < first_tank + 4) {
int decimals;
const char *unit;
const char *unit, *desc;
double gas_usage;
cylinder_t *cyl = dive->cylinder + n;
@ -242,23 +242,25 @@ static void print_tanks (struct dive *dive, cairo_t *cr, int maxwidth, int maxhe
/* Can we turn it into a volume? */
if (cyl->type.size.mliter) {
gas_usage = bar_to_atm(gas_usage / 1000);
gas_usage *= dive->cylinder[n].type.size.mliter;
gas_usage *= cyl->type.size.mliter;
gas_usage = get_volume_units(gas_usage, &decimals, &unit);
} else {
gas_usage = get_pressure_units(gas_usage, &unit);
decimals = 0;
}
curwidth = 0;
cairo_move_to (cr, curwidth / (double) PANGO_SCALE, 0);
snprintf(buffer, sizeof(buffer), "%s", dive->cylinder[n].type.description);
desc = cyl->type.description ? : "";
snprintf(buffer, sizeof(buffer), "%s", desc);
pango_layout_set_text(layout, buffer, -1);
pango_cairo_show_layout(cr, layout);
curwidth += (maxwidth/ 3);
cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
print_ean_trimix (cr, layout,
dive->cylinder[n].gasmix.o2.permille/10,
dive->cylinder[n].gasmix.he.permille/10);
cyl->gasmix.o2.permille/10,
cyl->gasmix.he.permille/10);
curwidth += (maxwidth/ 3);
cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);