]> granicus.if.org Git - python/commitdiff
Enhance _PyTime_AsTimespec()
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 3 Sep 2015 14:25:45 +0000 (16:25 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 3 Sep 2015 14:25:45 +0000 (16:25 +0200)
Ensure that the tv_nsec field is set, even if the function fails
with an overflow.

Python/pytime.c

index 8166ceccc55d4c5ba50b9ce084bad60e0d1a313d..cea3cf5d433a915cbdcf066f6f605e453df61183 100644 (file)
@@ -479,13 +479,13 @@ _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts)
         secs -= 1;
     }
     ts->tv_sec = (time_t)secs;
+    assert(0 <= nsec && nsec < SEC_TO_NS);
+    ts->tv_nsec = nsec;
+
     if ((_PyTime_t)ts->tv_sec != secs) {
         _PyTime_overflow();
         return -1;
     }
-    ts->tv_nsec = nsec;
-
-    assert(0 <= ts->tv_nsec && ts->tv_nsec < SEC_TO_NS);
     return 0;
 }
 #endif