[PATCH] Don't try to malloc a zero sized list

Linus Torvalds torvalds at linux-foundation.org
Thu Dec 11 18:06:44 PST 2014


On Thu, Dec 11, 2014 at 3:31 PM, Anton Lundin <glance at acc.umu.se> 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, &current_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


More information about the subsurface mailing list