]> granicus.if.org Git - python/commitdiff
Issue #22117: Add assertions to _PyTime_AsTimeval() and _PyTime_AsTimespec() to
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 30 Mar 2015 00:54:57 +0000 (02:54 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 30 Mar 2015 00:54:57 +0000 (02:54 +0200)
check that microseconds and nanoseconds fits into the specified range.

Python/pytime.c

index a7eda869a07ec07cd5591a70f17838da3344fdfa..0d28911c378600aa27e531d0700d33a878bb718d 100644 (file)
@@ -360,6 +360,8 @@ _PyTime_AsTimeval_impl(_PyTime_t t, struct timeval *tv, _PyTime_round_t round,
 
     if (res && raise)
         _PyTime_overflow();
+
+    assert(0 <= tv->tv_usec && tv->tv_usec <= 999999);
     return res;
 }
 
@@ -393,6 +395,8 @@ _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts)
         return -1;
     }
     ts->tv_nsec = nsec;
+
+    assert(0 <= ts->tv_nsec && ts->tv_nsec <= 999999999);
     return 0;
 }
 #endif