[PATCH v2] eal/windows: resolve conversion and truncation warnings

Tyler Retzlaff roretzla at linux.microsoft.com
Thu Mar 7 19:34:42 CET 2024


* 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 timespec.tv_nsec to long.

Signed-off-by: Tyler Retzlaff <roretzla at linux.microsoft.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk at gmail.com>
---

v2:
  * update commit message to correct misspelled timspec -> timespec,
    remove remarks about casting to long they were unnecessary.

 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



More information about the dev mailing list