diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-04-21 08:59:33 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-04-21 07:50:38 -0700 |
commit | a8aa8971176239fa4d428aaa4599d1f996e11885 (patch) | |
tree | 15c79f9a17de53b40e8c211588208fb44f55ccd1 /desktop-widgets/tab-widgets/TabDiveInformation.cpp | |
parent | 4aebcdc021391fcbdee089b5e14c11ebab517885 (diff) | |
download | subsurface-a8aa8971176239fa4d428aaa4599d1f996e11885.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/tab-widgets/TabDiveInformation.cpp')
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveInformation.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
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<int> 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; |