@@ -101,7 +101,8 @@ static int
101
101
_PyTime_ObjectToDenominator (PyObject * obj , time_t * sec , long * numerator ,
102
102
double denominator , _PyTime_round_t round )
103
103
{
104
- assert (denominator <= LONG_MAX );
104
+ assert (denominator <= (double )LONG_MAX );
105
+
105
106
if (PyFloat_Check (obj )) {
106
107
double d = PyFloat_AsDouble (obj );
107
108
return _PyTime_DoubleToDenominator (d , sec , numerator ,
@@ -149,14 +150,20 @@ int
149
150
_PyTime_ObjectToTimespec (PyObject * obj , time_t * sec , long * nsec ,
150
151
_PyTime_round_t round )
151
152
{
152
- return _PyTime_ObjectToDenominator (obj , sec , nsec , 1e9 , round );
153
+ int res ;
154
+ res = _PyTime_ObjectToDenominator (obj , sec , nsec , 1e9 , round );
155
+ assert (0 <= * nsec && * nsec < SEC_TO_NS );
156
+ return res ;
153
157
}
154
158
155
159
int
156
160
_PyTime_ObjectToTimeval (PyObject * obj , time_t * sec , long * usec ,
157
161
_PyTime_round_t round )
158
162
{
159
- return _PyTime_ObjectToDenominator (obj , sec , usec , 1e6 , round );
163
+ int res ;
164
+ res = _PyTime_ObjectToDenominator (obj , sec , usec , 1e6 , round );
165
+ assert (0 <= * usec && * usec < SEC_TO_US );
166
+ return res ;
160
167
}
161
168
162
169
static void
@@ -170,12 +177,13 @@ _PyTime_t
170
177
_PyTime_FromSeconds (int seconds )
171
178
{
172
179
_PyTime_t t ;
180
+ t = (_PyTime_t )seconds ;
173
181
/* ensure that integer overflow cannot happen, int type should have 32
174
182
bits, whereas _PyTime_t type has at least 64 bits (SEC_TO_MS takes 30
175
183
bits). */
176
- assert ((seconds >= 0 && seconds <= _PyTime_MAX / SEC_TO_NS )
177
- || (seconds < 0 && seconds >= _PyTime_MIN / SEC_TO_NS ));
178
- t = ( _PyTime_t ) seconds * SEC_TO_NS ;
184
+ assert ((t >= 0 && t <= _PyTime_MAX / SEC_TO_NS )
185
+ || (t < 0 && t >= _PyTime_MIN / SEC_TO_NS ));
186
+ t *= SEC_TO_NS ;
179
187
return t ;
180
188
}
181
189
0 commit comments