Skip to content

Commit 9bb758c

Browse files
committed
Issue #22043: Fix _PyTime_gettimeofday() if HAVE_GETTIMEOFDAY
Ensure also that the tv_usec field is consistent: in range [0; 999999].
1 parent 5791a54 commit 9bb758c

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Python/pytime.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info, int raise)
3737
info->resolution = timeIncrement * 1e-7;
3838
info->adjustable = 1;
3939
}
40-
return 0;
4140

4241
#else /* MS_WINDOWS */
4342
int err;
@@ -67,11 +66,9 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info, int raise)
6766
else
6867
info->resolution = 1e-9;
6968
}
70-
return 0;
7169
#else /* HAVE_CLOCK_GETTIME */
7270

7371
/* test gettimeofday() */
74-
#ifdef HAVE_GETTIMEOFDAY
7572
#ifdef GETTIMEOFDAY_NO_TZ
7673
err = gettimeofday(tp);
7774
#else
@@ -89,10 +86,10 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info, int raise)
8986
info->monotonic = 0;
9087
info->adjustable = 1;
9188
}
92-
return 0;
93-
#endif /* HAVE_GETTIMEOFDAY */
9489
#endif /* !HAVE_CLOCK_GETTIME */
9590
#endif /* !MS_WINDOWS */
91+
assert(0 <= tp->tv_usec && tp->tv_usec < 1000 * 1000);
92+
return 0;
9693
}
9794

9895
void

0 commit comments

Comments
 (0)