Messages in this thread | | | Date | Tue, 1 Sep 1998 06:37:26 -0500 | From | Mitchell Blank Jr <> | Subject | Re: 2.1.120pre2: Bug in strnicmp() noted in 2.1.119pre1 is still there! |
| |
Michal Jaegermann wrote: > closes negative 'len' hole.
Assuming that it's a "hole". It might be intentional (shrug). You'd probably always want to specify a length in kernel code. though.
> if (len <= 0) > return 0; > while (len) {
You could also just say that as c1 = c2 = 0; while (len > 0) {
You need to set c1=c2 so the subtraction comes out in the end, but this is cheaper than doing an extra compare. On most archs testing >0 is as cheap as testing !=0.
> "return (c1 - c2);" should be ok to safisfy specs,
Agreed. I already sent Linus a replacement strnicmp that does this (and it looked pretty similar to what you came up with too) We'll see what he does ;-)
> but if you insists > on returning a sign replace this with: > c1 =- c2; ^^ You mean -=. This isn't the 70's ;-)
> return c1 ? (c1 < 0 ? -1 : 1) : 0;
Uh, c1 was unsigned, this won't work. If you wanted to be a bastard you could do something like:
len = c1 - c2; /* Hey, it wasn't being used... fair game */ return len<0 ? -1 : len&1;
But I think the actual value is irrelevant... just returning c1-c2 should be fine.
-Mitch
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html
| |