OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 if (ts < last_ts_) { | 197 if (ts < last_ts_) { |
198 if (last_ts_ > 0xf0000000 && ts < 0x0fffffff) { | 198 if (last_ts_ > 0xf0000000 && ts < 0x0fffffff) { |
199 ++num_wrap_; | 199 ++num_wrap_; |
200 } | 200 } |
201 } | 201 } |
202 last_ts_ = ts; | 202 last_ts_ = ts; |
203 int64_t unwrapped_ts = ts + (num_wrap_ << 32); | 203 int64_t unwrapped_ts = ts + (num_wrap_ << 32); |
204 return unwrapped_ts; | 204 return unwrapped_ts; |
205 } | 205 } |
206 | 206 |
207 int64_t TmToSeconds(const std::tm& tm) { | |
208 static short int cumul_days[12] = {0, 31, 59, 90, 120, 151, | |
209 181, 212, 243, 273, 304, 334}; | |
210 | |
211 int year = tm.tm_year + 1900; | |
212 int month = tm.tm_mon; | |
213 int day = tm.tm_mday - 1; // Make 0-based like the rest. | |
214 int hour = tm.tm_hour; | |
215 int min = tm.tm_min; | |
216 int sec = tm.tm_sec; | |
217 | |
218 day += cumul_days[month]; | |
nisse-webrtc
2015/11/27 12:47:12
I think you get an out-of-bounds read for invalid
torbjorng (webrtc)
2015/11/30 15:23:31
Sure, this was intended as a low-level internal fu
| |
219 | |
220 // Add number of leap days between 1970 and the expiration year, inclusive. | |
221 day += ((year / 4 - 1970 / 4) - (year / 100 - 1970 / 100) + | |
222 (year / 400 - 1970 / 400)); | |
223 | |
224 // If expiration time is in a leap year, number of days depends on exact date. | |
225 if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) { | |
226 if (month <= 2 - 1) { // February or earlier (|month| is zero based). | |
227 day -= 1; | |
nisse-webrtc
2015/11/27 12:47:12
This is a bit subtle... +1 for a leap year would b
torbjorng (webrtc)
2015/11/30 15:23:31
Tried to clarify.
| |
228 } | |
229 } | |
230 | |
231 // Combine all variables into seconds from 1970-01-01 00:00 (except |month| | |
232 // which was accumulated into |day| above). | |
233 return (((static_cast<int64_t> | |
234 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; | |
235 } | |
236 | |
207 } // namespace rtc | 237 } // namespace rtc |
OLD | NEW |