]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-time: Allow NULL arg in clock_getres
authorAndrei Tatar <andrei@unikraft.io>
Tue, 7 Nov 2023 14:06:48 +0000 (15:06 +0100)
committerSimon Kuenzer <simon@unikraft.io>
Mon, 27 Nov 2023 21:31:06 +0000 (22:31 +0100)
This change fixes the behavior of clock_getres to not return an error
when receiving a NULL as its output argument, in accordance with docs.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Simon Kuenzer <simon@unikraft.io>
Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1154

lib/posix-time/time.c

index a34ef4781453b708e84f072aff492417f7546c7f..fbbd5c79a295d0100573c5d09d0a9d4b94da124f 100644 (file)
@@ -149,17 +149,14 @@ UK_SYSCALL_R_DEFINE(int, clock_getres, clockid_t, clk_id,
 {
        int error;
 
-       if (!tp) {
-               error = EFAULT;
-               goto out_error;
-       }
-
        switch (clk_id) {
        case CLOCK_MONOTONIC:
        case CLOCK_MONOTONIC_COARSE:
        case CLOCK_REALTIME:
-               tp->tv_sec = 0;
-               tp->tv_nsec = UKPLAT_TIME_TICK_NSEC;
+               if (tp) {
+                       tp->tv_sec = 0;
+                       tp->tv_nsec = UKPLAT_TIME_TICK_NSEC;
+               }
                break;
        default:
                error = EINVAL;