]> Kevux Git Server - fll/commitdiff
Bugfix: nanoseconds should become seconds when a second is at least reached.
authorKevin Day <thekevinday@gmail.com>
Sun, 11 Apr 2021 21:44:49 +0000 (16:44 -0500)
committerKevin Day <thekevinday@gmail.com>
Sun, 11 Apr 2021 21:44:49 +0000 (16:44 -0500)
When adding to nanoseconds would result in a value greater than or equal to a second, instead increment by 1 second.

level_3/controller/c/private-common.c

index 873ffc8cc173214ce605ad7d4a2619dc5827c969..ba392596e1684f3dabdc99a9a78da11c2f1cae19 100644 (file)
@@ -505,7 +505,14 @@ extern "C" {
     gettimeofday(&now, 0);
 
     time->tv_sec = now.tv_sec + seconds;
-    time->tv_nsec = now.tv_usec * 1000 + nanos;
+    time->tv_nsec = (now.tv_usec * 1000) + nanos;
+
+    // If tv_nsec is 1 second or greater, then increment seconds.
+    if (time->tv_nsec >= 1000000000) {
+      ++(time->tv_sec);
+
+      time->tv_nsec -= 1000000000;
+    }
   }
 #endif // _di_controller_time_