diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-10-29 13:24:56 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-10-29 13:24:56 -0700 |
commit | b74cc4f523841729a9a7eaec3d29252e740a259d (patch) | |
tree | e4ba8801544fb9759d9dfb91e18bf4192982159f /profile.c | |
parent | 28247d3baa9967fa39772c41077e714c4c533c82 (diff) | |
download | subsurface-b74cc4f523841729a9a7eaec3d29252e740a259d.tar.gz |
Fix use of uninitialized variable if there are no samples
When creating the plot_info, the 'entry' variable pointing to the last
plot_info data was not initialized (because there was no data to fill
in), and was then incorrectly used to fill in the last tank pressure.
We also used to look at 'dive->sample[0].cylinderindex' even if no
sample[0] necessarily existed.
Reported-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'profile.c')
-rw-r--r-- | profile.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -1010,7 +1010,7 @@ static struct plot_info *create_plot_info(struct dive *dive) pr_track_t *track_pr[MAX_CYLINDERS] = {NULL, }; pr_track_t *pr_track, *current; gboolean missing_pr = FALSE; - struct plot_data *entry; + struct plot_data *entry = NULL; pi = malloc(alloc_size); if (!pi) @@ -1043,7 +1043,7 @@ static struct plot_info *create_plot_info(struct dive *dive) for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) /* initialize the start pressures */ track_pr[cyl] = pr_track_alloc(dive->cylinder[cyl].start.mbar, -1); - current = track_pr[dive->sample[0].cylinderindex]; + current = track_pr[pi->entry[2].cylinderindex]; for (i = 0; i < dive->samples; i++) { entry = pi->entry + i + 2; @@ -1073,7 +1073,9 @@ static struct plot_info *create_plot_info(struct dive *dive) missing_pr |= !SENSOR_PRESSURE(entry); } - current->t_end = entry->sec; + if (entry) + current->t_end = entry->sec; + for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) { /* initialize the end pressures */ int pr = dive->cylinder[cyl].end.mbar; if (pr && track_pr[cyl]) { |