Skip to contentSkip to conversation

embarassing typo

PATCH Vicente Feito 2 participants 2 messages Mar 30, 2005

lore
Share & tools
lore
#0 lore raw

As long as the variable doesn't get overflowed you would have a negation, you shouldn't do dri_data[5] = ptr->dri * 0xff; if ptr->dri it's 255, but if ptr->dri = 1 i.e. (like is set in zr36050_setup) then you would be getting the negation, -1. the Direct rendering support is a flag afaik, so in this case I believe is a worthy C obfuscated negation code :)
btw, are you sure about this patch?I would contact the maintainer first, because and'ing that doesn't make much sense...
Disclaimer, all this is: AFAIK! :)

Quoted 30 lines · you
Quoted 11 lines · Måns Rullgård
Quoted 8 lines · Ronald S. Bultje

--- linux-2.6.5/drivers/media/video/zr36050.c.old 16 Sep 2004 22:53:27 -0000 1.2 +++ linux-2.6.5/drivers/media/video/zr36050.c 29 Mar 2005 20:30:23 -0000 @@ -419,7 +419,7 @@
dri_data[2] = 0x00;
dri_data[3] = 0x04;
dri_data[4] = ptr->dri >> 8;
- dri_data[5] = ptr->dri * 0xff;
+ dri_data[5] = ptr->dri & 0xff;

Hey, that's a nice obfuscation of a simple negation.

It's not a negation. This statement always assigns zero to dri_data[5] if dri_data is char[]. Looks like gcc isn't catching this problem.

Quoted 3 lines

BTW, when assigning to a char type, is the masking really necessary at all? I can't see that it should make a difference. Am I missing something subtle?

Well, it's a matter of readability mostly. For now at least, when char is always 8 bytes...

/mjt
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#1 lore raw
Quoted 18 lines · Vicente Feito
Quoted 11 lines · you
Quoted 10 lines · Måns Rullgård
Quoted 8 lines · Ronald S. Bultje

--- linux-2.6.5/drivers/media/video/zr36050.c.old 16 Sep 2004 22:53:27 -0000 1.2 +++ linux-2.6.5/drivers/media/video/zr36050.c 29 Mar 2005 20:30:23 -0000 @@ -419,7 +419,7 @@
dri_data[2] = 0x00;
dri_data[3] = 0x04;
dri_data[4] = ptr->dri >> 8;
- dri_data[5] = ptr->dri * 0xff;
+ dri_data[5] = ptr->dri & 0xff;

Quoted 6 lines
Quoted 1 line

Hey, that's a nice obfuscation of a simple negation.

It's not a negation. This statement always assigns zero to dri_data[5] if dri_data is char[]. Looks like gcc isn't catching this problem.

Quoted 8 lines

As long as the variable doesn't get overflowed you would have a negation, you shouldn't do dri_data[5] = ptr->dri * 0xff; if ptr->dri it's 255, but if ptr->dri = 1 i.e. (like is set in zr36050_setup) then you would be getting the negation, -1. the Direct rendering support is a flag afaik, so in this case I believe is a worthy C obfuscated negation code :)
btw, are you sure about this patch?I would contact the maintainer first, because and'ing that doesn't make much sense...

It seems pretty obvious to me, that the code is supposed to store the high byte in dri_data[4], and the low byte in dri_data[5]. Mistyping & as * doesn't seem too unlikely, either.

Signature · 2 lines
Måns Rullgård
[email protected]