mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[fix] TimeVal: add dbg:guard against incorrect subtraction order (#4669)
In principle, any negative subtraction result should be caused by a logical error.
This commit is contained in:
@@ -13,6 +13,7 @@ A simple module to module to compare and do arithmetic with time values.
|
||||
local tv_duration_seconds_float = tv_duration.sec + tv_duration.usec/1000000
|
||||
]]
|
||||
|
||||
local dbg = require("dbg")
|
||||
local util = require("ffi/util")
|
||||
|
||||
--[[--
|
||||
@@ -110,6 +111,12 @@ function TimeVal:__sub(time_b)
|
||||
return diff
|
||||
end
|
||||
|
||||
dbg:guard(TimeVal, '__sub',
|
||||
function(self, time_b)
|
||||
assert(self.sec > time_b.sec or (self.sec == time_b.sec and self.usec >= time_b.usec),
|
||||
"Subtract the first timeval from the latest, not vice versa.")
|
||||
end)
|
||||
|
||||
function TimeVal:__add(time_b)
|
||||
local sum = TimeVal:new{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user