Browse files

Use os:timestamp/0 for elapsed time

Commit 5b056e0 replaced the deprecated erlang:now/0 with
os:timestamp/0. Using the system time is the way most versions of ping
work. The disadvantage of the system time is that time skew may result
in a negative number.

To fix this, commit c424984 used erlang:monotonic_time/1.
erlang:monotic_time/1 may return negative integers and the code did not
take into account sign conversions when converting the value from an
erlang timestamp to binary.

Revert to using os:timestamp/0 for elapsed time calculations. The other
option is using signed values in the binary pattern matching. However,
use of the erlang timestamp() type should probably be replaced with an 8
or 12 byte integer.

Reported in:


Thanks @vimal7370!
  • Loading branch information...
1 parent dc126ca commit a40670f8ce0d2445d31764df9aae0fb0c429978e @msantos committed Jun 19, 2016
Showing with 1 addition and 10 deletions.
  1. +1 −10 src/gen_icmp.erl
@@ -750,16 +750,7 @@ flush_events(Ref) ->
gettime() ->
- try erlang:monotonic_time(micro_seconds) of
- N ->
- MegaSecs = N div 1000000000000,
- Secs = N div 1000000 - MegaSecs*1000000,
- MicroSecs = N rem 1000000,
- {MegaSecs, Secs, MicroSecs}
- catch
- error:undef ->
- os:timestamp()
- end.
+ os:timestamp().
timediff(T) ->
timediff(gettime(), T).

0 comments on commit a40670f

Please sign in to comment.