On Tue, Jan 27, 2015 at 4:02 PM, Tim Hentenaar <[email protected]> wrote: > if (server_config.auto_time) { > - tv.tv_sec = timeout_end - monotonic_sec(); > tv.tv_usec = 0; > + tv.tv_sec = 0; > + > + msec = monotonic_sec(); > + if (msec < timeout_end) > + tv.tv_sec = timeout_end - msec; > }
This is in fact buggy, with a non-obvious reason. monotonic_sec() returns a monotonically increasing second count, _with unknown base_. It may well start counting from a value close to overflowing, such as 0xffffff00. Imagine that timeout_end = monotonic_sec() + timeout; happened to overflow and evaluate to 0. The (monotonic_sec() < timeout_end) condition after this will always be false, which means that at *any* moment, code thinks that "timeout_end" has been reached. Wrong. if you want to ask "did we reach timeout_end?", you should calculate (monotonic_sec() - timeout_end) and look at its sign. _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
