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

Linus Torvalds torvalds at linux-foundation.org
Thu Dec 11 23:19:33 PST 2014


On Dec 11, 2014 11:07 PM, "Anton Lundin" <glance at acc.umu.se> wrote:
>
> So, should the right approach here be not to trust malloc returning NULL
> here and we explicitly set sample to null if s->samples == 0 ?

That sounds fine, yes.

Or just initialize the fields to zero/NULL and then do that

  if (!nr)
      return;

with the properly initialized state

> Another thought, taken how the current copy_samples looks, if you where
> to call prepare_sample(d) after a copy_samples(s, d), which copied more
> than 10 samples, too me it looks like prepare_sample would truncate the
> sample list because copy_samples doesn't set dc->alloc_samples.

On mobile right now, so I can't check, but yes, initializing alloc_samples
to the allocation size sounds right to me.

     Linus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20141211/631e1075/attachment.html>


More information about the subsurface mailing list