nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] check stat's result to avoid referencing unitialized da


From: Kamil Dudka
Subject: Re: [Nano-devel] check stat's result to avoid referencing unitialized data
Date: Tue, 09 Feb 2016 15:48:01 +0100
User-agent: KMail/4.14.10 (Linux/4.3.5-300.fc23.x86_64; KDE/4.14.16; x86_64; ; )

On Tuesday 09 February 2016 15:31:27 Benno Schulenberg wrote:
> On Mon, Feb 8, 2016, at 09:35, Kamil Dudka wrote:
> > On Saturday 06 February 2016 11:35:29 Benno Schulenberg wrote:
> > > So I think this part should be:
> > > 
> > > -       /* Update current_stat to reference the file as it is now. */
> > > -       if (openfile->current_stat == NULL)
> > > -           openfile->current_stat =
> > > -               (struct stat *)nmalloc(sizeof(struct stat));
> > > -       if (!openfile->mark_set)
> > > -           stat(realname, openfile->current_stat);
> > > +       if (!openfile->mark_set) {
> > > +           if (openfile->current_stat == NULL)
> > > +               openfile->current_stat =
> > > +                       (struct stat *)nmalloc(sizeof(struct stat));
> > > +
> > > +           /* Update the stat info to reflect the file as it is now. */
> > > +           if (stat(realname, openfile->current_stat) != 0) {
> > > +               free(openfile->current_stat);
> > > +               openfile->current_stat = NULL;
> > > +           }
> > > +       }
> > 
> > Looks good to me.
> 
> I've reworked the patch a bit to reduce the number of lines.
> See attached.

I am fine with your version of the patch.  Thank you for reworking it!

Kamil

> If you can think of a better name than 'stat_with_alloc',
> do let me know.
> 
> Benno



reply via email to

[Prev in Thread] Current Thread [Next in Thread]