On Thu, Dec 11, 2014 at 3:31 PM, Anton Lundin <[email protected]> wrote:
> If we tried to copy a divecomputer without samples, we where to malloc a
> zero sized blob. dives/test15.xml triggered this and it was found with
> valgrind.
This is *not* correct.
First off, allocating a zero-sized area is legal, although it
might/should return NULL. So the patch doesn't "fix" anything.
But worse, the patch *breaks* stuff, by now not initializing the
"d->samples" and "d->sample" fields at all.
And at least MainTab::acceptChanges() definitely expects
copy_samples() to properly initialize those fields, because lookie
here:
free(current_dive->dc.sample);
copy_samples(&displayed_dive.dc, ¤t_dive->dc);
notice how it just free'd the "sample" pointer, and your patch now
does not overwrite it if the new source dc has no samples.
So NAK. This patch is wrong.
Linus
_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface