From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 42DD05A0265 for ; Thu, 06 Jun 2024 12:10:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1717668601; bh=oWtsgkDsdW7kpBikt9q6Ro0rH3/ZY3iK9MycwIJBaiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UZ4WTGyfOYTS3Uv11SDXIi8gQk0q8g6hW5j8tRq21IBfwavl53aQ6iL/jf37ezVi5 CnzhTaCEwJHkq7EL6o0OHwn7OUVi07ZqH6ATWVLGCJ6ygmmKCDCGX9pxHh93xht8ak z7V8e+mH4Byfx0f5fNr43vLZsmNv3bAxTx0lDi/M8a3JAzoV473676vNm8xxDbtbsU DAsx+5ZYBYc8QZqtKPjSw2+PDKoqNJbAget6ERFcH1z5oYvKTpxNlpKhDPk9Qp/Kff 8GvGggOhayF50UWPlgEU/3uEgaULy5T6T6/xzkR5780Ltoy0S6G/lJDYRAIo6VrZdi SO1VphfFmJZ7Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Vw0ST5LgRz4x1d; Thu, 6 Jun 2024 20:10:01 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 9/9] util: Use 'long' to represent millisecond durations Date: Thu, 6 Jun 2024 20:09:49 +1000 Message-ID: <20240606100949.1250958-10-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240606100949.1250958-1-david@gibson.dropbear.id.au> References: <20240606100949.1250958-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: DRTSHPPOFWZPIL3BKMWHERLDISG4SZYJ X-Message-ID-Hash: DRTSHPPOFWZPIL3BKMWHERLDISG4SZYJ X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- util.c | 2 +- util.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/util.c b/util.c index 5e854a26..44461801 100644 --- a/util.c +++ b/util.c @@ -216,7 +216,7 @@ void sock_probe_mem(struct ctx *c) * * 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) { return (b->tv_nsec - a->tv_nsec) / 1000000 + diff --git a/util.h b/util.h index cf9c4b66..eebb027b 100644 --- a/util.h +++ b/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, uint32_t data); 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_clear(uint8_t *map, unsigned bit); bool bitmap_isset(const uint8_t *map, unsigned bit); -- 2.45.2