From a9e79489dc497c3b7db10aac7cb0bb95c94447b7 Mon Sep 17 00:00:00 2001 From: Alex Buynytskyy Date: Thu, 20 Dec 2018 10:09:43 -0800 Subject: [PATCH] Minor refactor to support strings with embedded zeros. Test: manual Change-Id: Iaece3003deb257cbcae65a23a4c4a1ccfd690d49 --- adb/adb_io.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adb/adb_io.cpp b/adb/adb_io.cpp index 6cc274bbe..e6fefdae2 100644 --- a/adb/adb_io.cpp +++ b/adb/adb_io.cpp @@ -38,7 +38,8 @@ bool SendProtocolString(int fd, const std::string& s) { // The cost of sending two strings outweighs the cost of formatting. // "adb sync" performance is affected by this. - return WriteFdFmt(fd, "%04x%.*s", length, length, s.c_str()); + auto str = android::base::StringPrintf("%04x", length).append(s); + return WriteFdExactly(fd, str); } bool ReadProtocolString(int fd, std::string* s, std::string* error) {