DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] eal/windows: resolve conversion and truncation warnings
@ 2023-08-02 20:48 Tyler Retzlaff
  2023-08-02 22:29 ` Dmitry Kozlyuk
  2024-03-07 18:34 ` [PATCH v2] " Tyler Retzlaff
  0 siblings, 2 replies; 8+ messages in thread
From: Tyler Retzlaff @ 2023-08-02 20:48 UTC (permalink / raw)
  To: dev
  Cc: Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam, Tyler Retzlaff

* Initialize const int NS_PER_SEC with an integer literal instead of
  double thereby avoiding implicit conversion from double to int.

* Cast the result of the expression assigned to timspec.tv_nsec to long.
  Windows builds generate integer truncation warning for this assignment
  since the result of the expression was 8 bytes (LONGLONG) but
  on Windows targets is 4 bytes. The value produced for the expression
  should safely fit in the long.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/eal/windows/include/rte_os_shim.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
index eda8113..19b12e9 100644
--- a/lib/eal/windows/include/rte_os_shim.h
+++ b/lib/eal/windows/include/rte_os_shim.h
@@ -87,7 +87,7 @@
 static inline int
 rte_clock_gettime(clockid_t clock_id, struct timespec *tp)
 {
-	const int NS_PER_SEC = 1E9;
+	const int NS_PER_SEC = 1000000000;
 	LARGE_INTEGER pf, pc;
 	LONGLONG nsec;
 
@@ -102,7 +102,7 @@
 
 		nsec = pc.QuadPart * NS_PER_SEC / pf.QuadPart;
 		tp->tv_sec = nsec / NS_PER_SEC;
-		tp->tv_nsec = nsec - tp->tv_sec * NS_PER_SEC;
+		tp->tv_nsec = (long)(nsec - tp->tv_sec * NS_PER_SEC);
 		return 0;
 	default:
 		return -1;
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-03-07 20:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-02 20:48 [PATCH] eal/windows: resolve conversion and truncation warnings Tyler Retzlaff
2023-08-02 22:29 ` Dmitry Kozlyuk
2023-08-02 22:41   ` Tyler Retzlaff
2023-08-02 23:44     ` Dmitry Kozlyuk
2023-08-03  0:30       ` Tyler Retzlaff
2024-03-07 18:34 ` [PATCH v2] " Tyler Retzlaff
2024-03-07 20:53   ` Bruce Richardson
2024-03-07 20:57     ` Tyler Retzlaff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).