chiark / gitweb /
integer arithmetic types: correct perhaps-possible negative timeout situation
[secnet.git] / site.c
diff --git a/site.c b/site.c
index 8ef8f5a6e44cea77d7aeef4c0360d7888b5742bb..c2a230383bc3ad45020091726364f26130d849c2 100644 (file)
--- a/site.c
+++ b/site.c
@@ -936,7 +936,8 @@ static inline void site_settimeout(uint64_t timeout, uint64_t *now,
                                   int *timeout_io)
 {
     if (timeout) {
-       uint64_t offset=timeout-*now;
+       int64_t offset=timeout-*now;
+       if (offset<0) offset=0;
        if (offset>INT_MAX) offset=INT_MAX;
        if (*timeout_io<0 || offset<*timeout_io)
            *timeout_io=offset;