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: Neal H. Walfield
Subject: Re: [PATCH 3/7] name_equal: return early from function if src null-terminates in the loop
Date: Fri, 13 Sep 2013 15:41:47 +0200
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (Goj┼Ź) APEL/10.8 Emacs/23.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)

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');



reply via email to

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