mirror of
https://passt.top/passt
synced 2024-12-22 13:45:32 +00:00
util: Use 'long' to represent millisecond durations
timespec_diff_ms() returns an int representing a duration in milliseconds. This will overflow in about 25 days when an int is 32 bits. The way we use this function, we're probably not going to get a result that long, but it's not outrageously implausible. Use a long for safety. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
f9e8ee0777
commit
3f63743a65
2
util.c
2
util.c
@ -216,7 +216,7 @@ void sock_probe_mem(struct ctx *c)
|
|||||||
*
|
*
|
||||||
* Return: difference in milliseconds
|
* Return: difference in milliseconds
|
||||||
*/
|
*/
|
||||||
int timespec_diff_ms(const struct timespec *a, const struct timespec *b)
|
long timespec_diff_ms(const struct timespec *a, const struct timespec *b)
|
||||||
{
|
{
|
||||||
if (a->tv_nsec < b->tv_nsec) {
|
if (a->tv_nsec < b->tv_nsec) {
|
||||||
return (b->tv_nsec - a->tv_nsec) / 1000000 +
|
return (b->tv_nsec - a->tv_nsec) / 1000000 +
|
||||||
|
2
util.h
2
util.h
@ -147,7 +147,7 @@ int sock_l4(const struct ctx *c, sa_family_t af, uint8_t proto,
|
|||||||
const void *bind_addr, const char *ifname, uint16_t port,
|
const void *bind_addr, const char *ifname, uint16_t port,
|
||||||
uint32_t data);
|
uint32_t data);
|
||||||
void sock_probe_mem(struct ctx *c);
|
void sock_probe_mem(struct ctx *c);
|
||||||
int timespec_diff_ms(const struct timespec *a, const struct timespec *b);
|
long timespec_diff_ms(const struct timespec *a, const struct timespec *b);
|
||||||
void bitmap_set(uint8_t *map, unsigned bit);
|
void bitmap_set(uint8_t *map, unsigned bit);
|
||||||
void bitmap_clear(uint8_t *map, unsigned bit);
|
void bitmap_clear(uint8_t *map, unsigned bit);
|
||||||
bool bitmap_isset(const uint8_t *map, unsigned bit);
|
bool bitmap_isset(const uint8_t *map, unsigned bit);
|
||||||
|
Loading…
Reference in New Issue
Block a user