grub-devel
[Top][All Lists]
Advanced

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

Re: Imminent bugfix release (1.97.1)


From: Duboucher Thomas
Subject: Re: Imminent bugfix release (1.97.1)
Date: Mon, 09 Nov 2009 22:13:18 +0100
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bean a écrit :
> 
> Hi,
> 
> This one work:
> 
> int
> auth_strcmp (const char *s1, const char *s2)
> {
>   int result = 0;
> 
>   while (1)
>     {
>       result += (*s1 != *s2);
>       if (*s1 == 0)
>       break;
> 
>       s1++;
>       s2++;
>     }
> 
>   return (result != 0);
> }
> 
> The trick is to compare the ending '\0' as well, so that partial match
> is not satisfied.
> 

        Yep, I like this one, but I would prefer using an OR instead of an ADD
(with a highly hypothetical integer overflow :p) and because it's nicer
in terms of pure logic.
        "The comparison beetwen s1 and s2 is false if *s1 is different from
*s2, or recursively if the comparison beetwen s1+1 and s2+1 is false"

int
auth_strcmp (const char *s1, const char *s2)
{
  int ret = 0;

  for (;;)
  {
    ret |= (*s1 != *s2);

    if (*s1 == '\0')
      break;

    s1++;
    s2++;
  }

  return ret;
}

        Also, because s1 and s2 have two differents roles, I think it would be
best to give them names that better suits them. ;)

        Thomas.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkr4he4ACgkQBV7eXqefhqj0kACgkgE60xJe5X/zpmXoPEd9SsT9
6H8An113fF03h0cndz2LpJvqnPyJ3EPx
=5MEi
-----END PGP SIGNATURE-----




reply via email to

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