Messages in this thread |  | | | Subject | Re: [BUG] settimeofday(2) succeeds for microsecond value more than USEC_PER_SEC and for negative value | | From | Urs Thuermann <> | | Date | 02 May 2003 20:06:13 +0200 |
| |
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/
|  |