-----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----- _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel