summaryrefslogtreecommitdiffstats
path: root/libdivecomputer.c
diff options
context:
space:
mode:
authorGravatar Anton Lundin <glance@acc.umu.se>2013-12-11 00:53:36 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-12-11 03:13:30 +0100
commit0812d2def2a8d2bcd0bf7b2646dade989d63ae44 (patch)
tree450a43d24b5ee0ed195ee083bca92dcc199f467e /libdivecomputer.c
parent5b61409358b31699e36eb9057f633a42f7fe6563 (diff)
downloadsubsurface-0812d2def2a8d2bcd0bf7b2646dade989d63ae44.tar.gz
Add some sanity checks
If first sample is not a DC_SAMPLE_TIME, we would have bin dereferencing a null pointer. This might actually never happen, unless we talk to a really weird dc, but this makes the static analyzer happier. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'libdivecomputer.c')
-rw-r--r--libdivecomputer.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libdivecomputer.c b/libdivecomputer.c
index 2dee1389d..98245fb9b 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -181,6 +181,13 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
*/
sample = dc->samples ? dc->sample+dc->samples-1 : NULL;
+ /*
+ * Ok, sanity check.
+ * If first sample is not a DC_SAMPLE_TIME, Allocate a sample for us
+ */
+ if (sample == NULL && type != DC_SAMPLE_TIME)
+ sample = prepare_sample(dc);
+
switch (type) {
case DC_SAMPLE_TIME:
if (sample) {