From 22dc7b84f091b392537ab51539c4277ad54416de Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 19 Dec 2017 23:39:24 +0100 Subject: [PATCH] Handle plot_info->nr <= 0 gracefully plot_info->nr should always be > 0. If this is not the case, write a message to stderr instead of crashing in add_plot_pressure(). This silences an use-of-uninitialized-variable warning. Signed-off-by: Berthold Stoeger --- core/profile.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/profile.c b/core/profile.c index 327956cd5..e463c9c2b 100644 --- a/core/profile.c +++ b/core/profile.c @@ -805,6 +805,10 @@ static void populate_secondary_sensor_data(struct divecomputer *dc, struct plot_ static void add_plot_pressure(struct plot_info *pi, int time, int cyl, pressure_t p) { struct plot_data *entry; + if (pi->nr <= 0) { + fprintf(stderr, "add_plot_pressure(): called with pi->nr <= 0\n"); + return; + } for (int i = 0; i < pi->nr; i++) { entry = pi->entry + i;