From a8aa8971176239fa4d428aaa4599d1f996e11885 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 21 Apr 2020 08:59:33 +0200 Subject: [PATCH] desktop: don't access first data element if no cylinders TabDiveInformation::updateProfile() does some statistics via the per_cylinder_mean_depth function. It passes down arrays with one entry per cylinder, which are allocated by means std::vector. To pass the array, the expression "&vector[0]" is used. It seems like some compilers through an assertion violation if vector has no elements. They are technically correct in that this is undefined, but still this appears like very unfriendly behavior. After all, std::vector should behave just like a dynamic C-array that is automatically freed, when going out of scope. Replace the "&vector[0]" by "vector.data()" and don't do the call if there aren't any cylinders for good measure. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/TabDiveInformation.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp index f7d16fe26..f787c922e 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp +++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp @@ -128,7 +128,8 @@ void TabDiveInformation::updateProfile() volume_t *gases = get_gas_used(current_dive); QString volumes; std::vector mean(current_dive->cylinders.nr), duration(current_dive->cylinders.nr); - per_cylinder_mean_depth(current_dive, select_dc(current_dive), &mean[0], &duration[0]); + if (current_dive->cylinders.nr >= 0) + per_cylinder_mean_depth(current_dive, select_dc(current_dive), mean.data(), duration.data()); volume_t sac; QString gaslist, SACs, separator;