From 8f19becb620a6fedd0f8b855b48cdeeab211c2ed Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sat, 30 May 2020 11:05:53 +0200 Subject: code format --- src/afl-common.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'src/afl-common.c') diff --git a/src/afl-common.c b/src/afl-common.c index 793041b2..b3933b9c 100644 --- a/src/afl-common.c +++ b/src/afl-common.c @@ -880,7 +880,6 @@ void set_nonblocking(int fd) { } - /* Wrapper for select() and read(), reading exactly len bytes. Should be called on non-blocking fds. Returns the time passed to read. @@ -895,24 +894,24 @@ u32 read_timed(s32 fd, void *buf, size_t len, u32 timeout_ms, FD_ZERO(&readfds); FD_SET(fd, &readfds); - size_t read_total = 0; + size_t read_total = 0; ssize_t len_read = 0; - #if defined(__linux__) - timeout.tv_sec = (timeout_ms / 1000); - timeout.tv_usec = (timeout_ms % 1000) * 1000; - #else - u64 time_start = get_cur_time_us(); - #endif +#if defined(__linux__) + timeout.tv_sec = (timeout_ms / 1000); + timeout.tv_usec = (timeout_ms % 1000) * 1000; +#else + u64 time_start = get_cur_time_us(); +#endif while (read_total < len) { - #if !defined(__linux__) - u64 time_current = get_cur_time_us(); - u64 timeout_current = timeout_ms - (time_current - time_start); - timeout.tv_sec = (timeout_current / 1000); - timeout.tv_usec = (timeout_current % 1000) * 1000; - #endif +#if !defined(__linux__) + u64 time_current = get_cur_time_us(); + u64 timeout_current = timeout_ms - (time_current - time_start); + timeout.tv_sec = (timeout_current / 1000); + timeout.tv_usec = (timeout_current % 1000) * 1000; +#endif /* set exceptfds as well to return when a child exited/closed the pipe. */ int sret = select(fd + 1, &readfds, NULL, NULL, &timeout); @@ -936,13 +935,13 @@ u32 read_timed(s32 fd, void *buf, size_t len, u32 timeout_ms, } - #if defined(__linux__) - s32 exec_ms = +#if defined(__linux__) + s32 exec_ms = MIN(timeout_ms, ((u64)timeout_ms - (timeout.tv_sec * 1000 + timeout.tv_usec / 1000))); - #else - u32 exec_ms = get_cur_time_us() - time_start; - #endif +#else + u32 exec_ms = get_cur_time_us() - time_start; +#endif return exec_ms > 0 ? exec_ms : 1; // at least 1 milli must have passed (0 is an error) -- cgit 1.4.1