Re: [BUG] settimeofday(2) succeeds for microsecond value more than USEC_PER_SEC and for negative value

From: Urs Thuermann (urs@isnogud.escape.de)
Date: Fri May 02 2003 - 13:06:13 EST


george anzinger <george@mvista.com> writes:

> Uh, sure. This is the test I prefer:
>
> if( (unsigned long)tv->usec > USEC_PER_SEC)
> return EINVAL;
>
> Note that the unsigned picks up the negative value as well as the >
> (and it does it in only one machine code test/jmp :)

No, don't do the compilers job. Just write

        if (tv->usec < 0 || tv->usec >= USEC_PER_SEC) { ... }

This is easier to read, portable, and generates the same machine code
as your C code, at least in all gcc versions since gcc-2.7.2.3 (I
don't have older gcc versions here on my machine to test).

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



This archive was generated by hypermail 2b29 : Wed May 07 2003 - 22:00:16 EST