On Tue, Nov 10, 2009 at 4:46 PM, Bean <[email protected]> wrote:
> Hi,
>
> Just in case p2 is optimized out by gcc:
>
> typedef char grub_password_t[1024];
>
> int
> grub_auth_strcmp (const grub_password_t s1, const grub_password_t s2)
> {
> char r1 = 0;
> char r2 = 0;
> char r3 = 0;
> char *p1, *p2;
> int i;
>
> p1 = &r1;
> p2 = &r3;
> for (i = 0; i < sizeof (grub_password_t); i++, s1++, s2++)
> {
> *p1 |= (*s1 ^ *s2);
> if (*s1 == '\0')
> p1 = &r2;
> else
> p2 = &r2;
> (*p2)++;
> }
>
> return (r1 != 0);
> }
Hi,
Perhaps this one, it's more symmetrical:
typedef char grub_password_t[1024];
int
grub_auth_strcmp (const grub_password_t s1, const grub_password_t s2)
{
char r1 = 0;
char r2 = 0;
char r3 = 0;
char *p1, *p2;
int i;
p1 = &r1;
p2 = &r3;
for (i = 0; i < sizeof (grub_password_t); i++, s1++, s2++)
{
char c;
c = (*s1 ^ *s2);
*p1 |= c;
*p2 |= c;
if (*s1 == '\0')
p1 = &r2;
else
p2 = &r2;
}
return (r1 != 0);
}
--
Bean
My repository: https://launchpad.net/burg
Document: https://help.ubuntu.com/community/Burg
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel