mirror of
https://github.com/Genymobile/scrcpy
synced 2025-01-03 05:02:07 +00:00
Cast to sc_tick type in conversion macros
With the old macros definitions, the type of the result depended on the type of `sec`. In particular, if sec is a 32-bit type, sec * 1000000 was likely to overflow (even if the result was assigned to a sc_tick by the caller of the macro). This was the case on Windows, where the long type is a 32-bit signed integer: the --time-limit argument, expressed in seconds, was first parsed to a long value, then multiplied by 1000000 by the SC_TICK_FROM_SEC() macro, causing an overflow when the value was greater than 2147 (2^31 / 1000000). Fixes #5355 <https://github.com/Genymobile/scrcpy/issues/5355>
This commit is contained in:
parent
5b10650f22
commit
afbaf59abb
@ -10,14 +10,14 @@ typedef int64_t sc_tick;
|
||||
#define SC_TICK_FREQ 1000000 // microsecond
|
||||
|
||||
// To be adapted if SC_TICK_FREQ changes
|
||||
#define SC_TICK_TO_NS(tick) ((tick) * 1000)
|
||||
#define SC_TICK_TO_US(tick) (tick)
|
||||
#define SC_TICK_TO_MS(tick) ((tick) / 1000)
|
||||
#define SC_TICK_TO_SEC(tick) ((tick) / 1000000)
|
||||
#define SC_TICK_FROM_NS(ns) ((ns) / 1000)
|
||||
#define SC_TICK_FROM_US(us) (us)
|
||||
#define SC_TICK_FROM_MS(ms) ((ms) * 1000)
|
||||
#define SC_TICK_FROM_SEC(sec) ((sec) * 1000000)
|
||||
#define SC_TICK_TO_NS(tick) ((sc_tick) (tick) * 1000)
|
||||
#define SC_TICK_TO_US(tick) ((sc_tick) tick)
|
||||
#define SC_TICK_TO_MS(tick) ((sc_tick) (tick) / 1000)
|
||||
#define SC_TICK_TO_SEC(tick) ((sc_tick) (tick) / 1000000)
|
||||
#define SC_TICK_FROM_NS(ns) ((sc_tick) (ns) / 1000)
|
||||
#define SC_TICK_FROM_US(us) ((sc_tick) us)
|
||||
#define SC_TICK_FROM_MS(ms) ((sc_tick) (ms) * 1000)
|
||||
#define SC_TICK_FROM_SEC(sec) ((sc_tick) (sec) * 1000000)
|
||||
|
||||
sc_tick
|
||||
sc_tick_now(void);
|
||||
|
Loading…
Reference in New Issue
Block a user