Skip to content

Commit 29ee674

Browse files
committed
Enhance _PyTime_AsTimespec()
Ensure that the tv_nsec field is set, even if the function fails with an overflow.
1 parent fbb215c commit 29ee674

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Python/pytime.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,13 @@ _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts)
479479
secs -= 1;
480480
}
481481
ts->tv_sec = (time_t)secs;
482+
assert(0 <= nsec && nsec < SEC_TO_NS);
483+
ts->tv_nsec = nsec;
484+
482485
if ((_PyTime_t)ts->tv_sec != secs) {
483486
_PyTime_overflow();
484487
return -1;
485488
}
486-
ts->tv_nsec = nsec;
487-
488-
assert(0 <= ts->tv_nsec && ts->tv_nsec < SEC_TO_NS);
489489
return 0;
490490
}
491491
#endif

0 commit comments

Comments
 (0)