bug-hurd
[Top][All Lists]
Advanced

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

Re: [PATCH 3/7] name_equal: return early from function if src null-termi


From: Marin Ramesa
Subject: Re: [PATCH 3/7] name_equal: return early from function if src null-terminates in the loop
Date: Fri, 13 Sep 2013 16:59:02 +0200

On 13.09.2013 15:41:47, Neal H. Walfield wrote:
> At Fri, 13 Sep 2013 15:06:33 +0200,
> Marin Ramesa wrote:
> > 
> > On 13.09.2013 14:42:44, Neal H. Walfield wrote:
> > > At Fri, 13 Sep 2013 13:31:53 +0200,
> > > Marin Ramesa wrote:
> > > > diff --git a/device/dev_name.c b/device/dev_name.c
> > > > index bf541df..6ce4b19 100644
> > > > --- a/device/dev_name.c
> > > > +++ b/device/dev_name.c
> > > > @@ -69,9 +69,12 @@ name_equal(src, len, target)
> > > >         int     len;
> > > >         char    *target;
> > > >  {
> > > > -       while (--len >= 0)
> > > > +       while (--len >= 0) {
> > > >             if (*src++ != *target++)
> > > >                 return FALSE;
> > > > +           if (*src == '\0' && *target != '\0')
> > > > +               return FALSE;
> > > > +       }
> > > 
> > > Shouldn't this return TRUE?
> > > 
> > > Neal
> > 
> > I don't think so. The function tests if 'src' and 'target' are 
> > equal for 'len' characters, so if 'src' null-terminates inside the 
> > loop and 'target' doesn't, it means that they are not equal (btw in 
> > the comments it says that 'target' is sure to be null-terminated).
> 
> This is clearer, I think:
> 
> if (*src == '\0' || *target == '\0')
>   return (*src == '\0' && *target == '\0');

Yes. I think that's a better solution. It takes care of the case when 
target null-terminates in the loop.


reply via email to

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