@@ -80,8 +80,11 @@ static int icaltime_leap_days(int y1, int y2)
80
80
* in that we don't want the automatic adjustments for
81
81
* local daylight savings time applied to the result.
82
82
* This function expects well-formed input.
83
+ *
84
+ * The out_time_t is to store the result, it can be NULL.
85
+ * Returns 0 on failure, 1 on success.
83
86
*/
84
- static time_t make_time (const struct tm * tm , int tzm )
87
+ static int make_time (const struct tm * tm , int tzm , time_t * out_time_t )
85
88
{
86
89
time_t tim ;
87
90
int febs ;
@@ -91,29 +94,29 @@ static time_t make_time(const struct tm *tm, int tzm)
91
94
/* check that month specification within range */
92
95
93
96
if (tm -> tm_mon < 0 || tm -> tm_mon > 11 )
94
- return (( time_t ) - 1 ) ;
97
+ return 0 ;
95
98
96
99
if (tm -> tm_year < 2 )
97
- return (( time_t ) - 1 ) ;
100
+ return 0 ;
98
101
99
102
#if (SIZEOF_TIME_T == 4 )
100
103
/* check that year specification within range */
101
104
102
105
if (tm -> tm_year > 138 )
103
- return (( icaltime_t ) - 1 ) ;
106
+ return 0 ;
104
107
105
108
/* check for upper bound of Jan 17, 2038 (to avoid possibility of 32-bit arithmetic overflow) */
106
109
if (tm -> tm_year == 138 ) {
107
110
if (tm -> tm_mon > 0 ) {
108
- return (( time_t ) - 1 ) ;
111
+ return 0 ;
109
112
} else if (tm -> tm_mday > 17 ) {
110
- return (( time_t ) - 1 ) ;
113
+ return 0 ;
111
114
}
112
115
}
113
116
#else
114
117
/* We don't support years >= 10000, because the function has not been tested at this range. */
115
118
if (tm -> tm_year >= 8100 ) {
116
- return (( time_t ) - 1 ) ;
119
+ return 0 ;
117
120
}
118
121
#endif /* SIZEOF_TIME_T */
119
122
@@ -162,7 +165,10 @@ static time_t make_time(const struct tm *tm, int tzm)
162
165
163
166
/* return number of seconds since start of the epoch */
164
167
165
- return (tim );
168
+ if (out_time_t )
169
+ * out_time_t = tim ;
170
+
171
+ return 1 ;
166
172
}
167
173
168
174
/*
@@ -177,7 +183,7 @@ static time_t icaltime_timegm(const struct tm *tm)
177
183
time_t seconds ;
178
184
179
185
/* Validate the tm structure by passing it through make_time() */
180
- if (make_time (tm , 0 ) < 0 ) {
186
+ if (! make_time (tm , 0 , NULL ) ) {
181
187
/* we have some invalid data in the tm struct */
182
188
return 0 ;
183
189
}
@@ -249,7 +255,7 @@ struct icaltimetype icaltime_today(void)
249
255
time_t icaltime_as_timet (const struct icaltimetype tt )
250
256
{
251
257
struct tm stm ;
252
- time_t t ;
258
+ time_t t = ( time_t ) - 1 ;
253
259
254
260
/* If the time is the special null time, return 0. */
255
261
if (icaltime_is_null_time (tt )) {
@@ -272,7 +278,8 @@ time_t icaltime_as_timet(const struct icaltimetype tt)
272
278
stm .tm_year = tt .year - 1900 ;
273
279
stm .tm_isdst = -1 ;
274
280
275
- t = make_time (& stm , 0 );
281
+ if (!make_time (& stm , 0 , & t ))
282
+ t = ((time_t )- 1 );
276
283
277
284
return t ;
278
285
}
0 commit comments