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

Unified Diff: net/der/input_unittest.cc

Issue 1160643002: Remove dangerous std::string constructor for der::Input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix null-terminated strings bug, and use a static factory method instead of another constructor Created 5 years, 7 months 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 side-by-side diff with in-line comments
Download patch
Index: net/der/input_unittest.cc
diff --git a/net/der/input_unittest.cc b/net/der/input_unittest.cc
index dc58d4b0d0399094584254b06c1c84713b057f70..a72fae91a1ea6f59b3484c4178b88280241ac119 100644
--- a/net/der/input_unittest.cc
+++ b/net/der/input_unittest.cc
@@ -17,8 +17,8 @@ TEST(InputTest, Equals) {
Input test2(kInput, arraysize(kInput));
EXPECT_TRUE(test.Equals(test2));
- std::string input_copy(reinterpret_cast<const char*>(kInput),
- arraysize(kInput));
+ uint8_t input_copy[arraysize(kInput)] = {0};
+ memcpy(input_copy, kInput, arraysize(kInput));
Ryan Sleevi 2015/05/26 18:53:30 It's unclear what this is testing or why it's nece
nharper 2015/05/26 22:11:49 It's testing that 2 Inputs are equal that point to
Input test_copy(input_copy);
EXPECT_TRUE(test.Equals(test_copy));
@@ -35,6 +35,15 @@ TEST(InputTest, StaticArray) {
EXPECT_TRUE(input.Equals(input2));
}
+TEST(InputTest, FromCString) {
+ Input from_array(kInput);
+ Input from_string = Input::FromCString("test");
+ EXPECT_TRUE(from_array.Equals(from_string));
+
+ Input zero_length = Input::FromCString("");
+ EXPECT_EQ(0u, zero_length.Length());
+}
+
TEST(ByteReaderTest, NoReadPastEnd) {
ByteReader reader(Input(nullptr, 0));
uint8_t data;
@@ -85,7 +94,7 @@ TEST(ByteReaderTest, ReadToMark) {
TEST(ByteReaderTest, CantReadToWrongMark) {
Input out;
Input in1(kInput, arraysize(kInput));
- Input in2("test");
+ Input in2 = Input::FromCString("test");
ByteReader reader1(in1);
ByteReader reader2(in2);
ASSERT_TRUE(reader1.ReadBytes(2, &out));
« net/der/input.h ('K') | « net/der/input.cc ('k') | net/der/parse_values_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698