From 982eee7f311d49c86d6624eb28ea71fbe66e8742 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 20 Jun 2023 15:34:11 -0700 Subject: [PATCH] libsysprof-analyze: return NULL if series is empty --- src/libsysprof-analyze/sysprof-time-series.c | 6 +++++- src/libsysprof-analyze/sysprof-xy-series.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libsysprof-analyze/sysprof-time-series.c b/src/libsysprof-analyze/sysprof-time-series.c index 1f24233a..9ecb5fad 100644 --- a/src/libsysprof-analyze/sysprof-time-series.c +++ b/src/libsysprof-analyze/sysprof-time-series.c @@ -150,7 +150,11 @@ sysprof_time_series_get_values (const SysprofTimeSeries *self, guint *n_values) { *n_values = self->values->len; - return &g_array_index (self->values, SysprofTimeSeriesValue, 0); + + if (self->values->len > 0) + return &g_array_index (self->values, SysprofTimeSeriesValue, 0); + + return NULL; } static int diff --git a/src/libsysprof-analyze/sysprof-xy-series.c b/src/libsysprof-analyze/sysprof-xy-series.c index e6eb5a42..7399bc4c 100644 --- a/src/libsysprof-analyze/sysprof-xy-series.c +++ b/src/libsysprof-analyze/sysprof-xy-series.c @@ -169,7 +169,11 @@ sysprof_xy_series_get_values (const SysprofXYSeries *self, guint *n_values) { *n_values = self->values->len; - return &g_array_index (self->values, SysprofXYSeriesValue, 0); + + if (self->values->len > 0) + return &g_array_index (self->values, SysprofXYSeriesValue, 0); + + return NULL; } static int