Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: base/time/time_unittest.cc

Issue 2405453002: Fix Integer-overflow in base::Time::FromExploded. (Closed)
Patch Set: rebased and fixed net unittest Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/time/time_posix.cc ('k') | base/time/time_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/time/time.h" 5 #include "base/time/time.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <time.h> 8 #include <time.h>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // Negative milliseconds 47 // Negative milliseconds
48 {{2016, 10, 0, 25, 7, 47, 20, -500}, false}, 48 {{2016, 10, 0, 25, 7, 47, 20, -500}, false},
49 // Hours are too large 49 // Hours are too large
50 {{2016, 7, 0, 10, 26, 29, 0, 0}, false}, 50 {{2016, 7, 0, 10, 26, 29, 0, 0}, false},
51 // Minutes are too large 51 // Minutes are too large
52 {{2016, 3, 0, 14, 10, 78, 0, 0}, false}, 52 {{2016, 3, 0, 14, 10, 78, 0, 0}, false},
53 // Seconds are too large 53 // Seconds are too large
54 {{2016, 10, 0, 25, 7, 47, 234, 0}, false}, 54 {{2016, 10, 0, 25, 7, 47, 234, 0}, false},
55 // Milliseconds are too large 55 // Milliseconds are too large
56 {{2016, 10, 0, 25, 6, 31, 23, 1643}, false}, 56 {{2016, 10, 0, 25, 6, 31, 23, 1643}, false},
57 // Test overflow. Time is valid, but overflow case
58 // results in Time(0).
59 {{9840633, 1, 0, 1, 1, 1, 0, 0}, true},
60 // Underflow will fail as well.
61 {{-9840633, 1, 0, 1, 1, 1, 0, 0}, true},
57 }; 62 };
58 63
59 for (const auto& test : kDateTestData) { 64 for (const auto& test : kDateTestData) {
60 EXPECT_EQ(test.explode.HasValidValues(), test.is_valid); 65 EXPECT_EQ(test.explode.HasValidValues(), test.is_valid);
61 66
62 base::Time result; 67 base::Time result;
63 EXPECT_FALSE(base::Time::FromUTCExploded(test.explode, &result)); 68 EXPECT_FALSE(base::Time::FromUTCExploded(test.explode, &result));
64 EXPECT_TRUE(result.is_null()); 69 EXPECT_TRUE(result.is_null());
65 EXPECT_FALSE(base::Time::FromLocalExploded(test.explode, &result)); 70 EXPECT_FALSE(base::Time::FromLocalExploded(test.explode, &result));
66 EXPECT_TRUE(result.is_null()); 71 EXPECT_TRUE(result.is_null());
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 1185
1181 TEST(TimeTicksLogging, DoesNotMakeStreamBad) { 1186 TEST(TimeTicksLogging, DoesNotMakeStreamBad) {
1182 std::ostringstream oss; 1187 std::ostringstream oss;
1183 oss << TimeTicks(); 1188 oss << TimeTicks();
1184 EXPECT_TRUE(oss.good()); 1189 EXPECT_TRUE(oss.good());
1185 } 1190 }
1186 1191
1187 } // namespace 1192 } // namespace
1188 1193
1189 } // namespace base 1194 } // namespace base
OLDNEW
« no previous file with comments | « base/time/time_posix.cc ('k') | base/time/time_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698