[libc-commits] [libc] 10fb71b - [libc] Fix test passing negative value in timespec passed to nanosleep (#65346)

via libc-commits libc-commits at lists.llvm.org
Wed Sep 6 11:28:35 PDT 2023


Author: Mikhail R. Gadelha
Date: 2023-09-06T14:28:31-04:00
New Revision: 10fb71bdff587d38d373b2dbcff33334bd7c66d1

URL: https://github.com/llvm/llvm-project/commit/10fb71bdff587d38d373b2dbcff33334bd7c66d1
DIFF: https://github.com/llvm/llvm-project/commit/10fb71bdff587d38d373b2dbcff33334bd7c66d1.diff

LOG: [libc] Fix test passing negative value in timespec passed to nanosleep (#65346)

This test was setting tv_nsec to a negative value, which as per the
standard this is an EINVAL:

The value in the tv_nsec field was not in the range [0, 999999999] or
tv_sec was negative.

https://man7.org/linux/man-pages/man2/nanosleep.2.html

Added: 
    

Modified: 
    libc/test/src/time/gettimeofday_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/src/time/gettimeofday_test.cpp b/libc/test/src/time/gettimeofday_test.cpp
index 5edd61c6483697..a852d4fd30ef12 100644
--- a/libc/test/src/time/gettimeofday_test.cpp
+++ b/libc/test/src/time/gettimeofday_test.cpp
@@ -25,7 +25,7 @@ TEST(LlvmLibcGettimeofday, SmokeTest) {
     int ret = __llvm_libc::gettimeofday(&tv, tz);
     ASSERT_EQ(ret, 0);
 
-    int sleep_time = -sleep_times[i];
+    int sleep_time = sleep_times[i];
     // Sleep for {sleep_time} microsceconds.
     struct timespec tim = {0, sleep_time * 1000};
     struct timespec tim2 = {0, 0};


        


More information about the libc-commits mailing list