diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2016-10-20 04:32:51 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-10-20 04:32:52 +0000 |
commit | 1edd61ce5d2f34ff34d015643b5915b3b1c186e8 (patch) | |
tree | 930fa23afba636c17d53918db82b3a4ac4252dfd /adb/shell_service_protocol_test.cpp | |
parent | 6da6d37c819ece275bac7df1204cdf3693ab71f7 (diff) | |
parent | ef57d54f80774701eee8bdb45185fb33e5ced473 (diff) | |
download | system_core-1edd61ce5d2f34ff34d015643b5915b3b1c186e8.tar.gz system_core-1edd61ce5d2f34ff34d015643b5915b3b1c186e8.tar.bz2 system_core-1edd61ce5d2f34ff34d015643b5915b3b1c186e8.zip |
Merge "adb: fix undefined behavior"
Diffstat (limited to 'adb/shell_service_protocol_test.cpp')
-rw-r--r-- | adb/shell_service_protocol_test.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/adb/shell_service_protocol_test.cpp b/adb/shell_service_protocol_test.cpp index a826035ab..b0fa3edbb 100644 --- a/adb/shell_service_protocol_test.cpp +++ b/adb/shell_service_protocol_test.cpp @@ -86,9 +86,10 @@ sig_t ShellProtocolTest::saved_sigpipe_handler_ = nullptr; namespace { -// Returns true if the packet contains the given values. +// Returns true if the packet contains the given values. `data` can't be null. bool PacketEquals(const ShellProtocol* protocol, ShellProtocol::Id id, const void* data, size_t data_length) { + // Note that passing memcmp null is bad, even if data_length is 0. return (protocol->id() == id && protocol->data_length() == data_length && !memcmp(data, protocol->data(), data_length)); @@ -130,7 +131,8 @@ TEST_F(ShellProtocolTest, ZeroLengthPacket) { ASSERT_TRUE(write_protocol_->Write(id, 0)); ASSERT_TRUE(read_protocol_->Read()); - ASSERT_TRUE(PacketEquals(read_protocol_, id, nullptr, 0)); + char buf[1]; + ASSERT_TRUE(PacketEquals(read_protocol_, id, buf, 0)); } // Tests exit code packets. |