core: use num in alloc_samples

When num > dc->alloc_samples we whould allocate space for num

Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
jan Iversen 2018-06-19 20:27:30 +02:00 committed by Dirk Hohndel
parent 44a9b26889
commit cabc5859fd

View file

@ -747,7 +747,7 @@ void copy_samples(struct divecomputer *s, struct divecomputer *d)
void alloc_samples(struct divecomputer *dc, int num)
{
if (num > dc->alloc_samples) {
dc->alloc_samples = (dc->alloc_samples * 3) / 2 + 10;
dc->alloc_samples = (num * 3) / 2 + 10;
dc->sample = realloc(dc->sample, dc->alloc_samples * sizeof(struct sample));
if (!dc->sample)
dc->samples = dc->alloc_samples = 0;