From 1e1ae45a8c24ac4ef390a731c65fcf4e6a206306 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 15 Mar 2019 14:49:25 -0700 Subject: [PATCH] adb: avoid sign extension of shell return code. Windows has int32_t return codes, which results in return codes 128-255 being sign extended into a negative number. Manually truncate the return codes we get to preserve their values. Test: test_device.py on windows Change-Id: If41d6d469350301704f6ecff72ad17b412db3e04 --- adb/client/commandline.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adb/client/commandline.cpp b/adb/client/commandline.cpp index bb30ae570..43a3e5e94 100644 --- a/adb/client/commandline.cpp +++ b/adb/client/commandline.cpp @@ -295,7 +295,10 @@ int read_and_dump(int fd, bool use_shell_protocol = false, callback->OnStderr(buffer_ptr, length); break; case ShellProtocol::kIdExit: - exit_code = protocol->data()[0]; + // data() returns a char* which doesn't have defined signedness. + // Cast to uint8_t to prevent 255 from being sign extended to INT_MIN, + // which doesn't get truncated on Windows. + exit_code = static_cast(protocol->data()[0]); continue; default: continue;