lkml.org 
[lkml]   [2003]   [May]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [BUG] settimeofday(2) succeeds for microsecond value more than USEC_PER_SEC and for negative value
From
Date
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/

\
 
 \ /
  Last update: 2005-03-22 13:35    [from the cache]
©2003-2011 Jasper Spaans