fastboot device: Disallow implicit conversion from unique_fd to int.

Do not use the implicit cast from unique_fd to int so
that it is clearer to the reader what the ownership model
is.

Test: pass
Change-Id: I66563eb2bd06f6a712a5afd4c6009f9b25a55de6
This commit is contained in:
Yifan Hong 2021-03-22 19:21:34 -07:00
parent 58532dfacd
commit 07e947fc5d
4 changed files with 6 additions and 5 deletions

View File

@ -127,6 +127,7 @@ cc_defaults {
"-Wextra",
"-Werror",
"-Wvla",
"-DANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION",
],
rtti: true,

View File

@ -392,13 +392,13 @@ static bool EnterRecovery() {
struct sockaddr_un addr = {.sun_family = AF_UNIX};
strncpy(addr.sun_path, "/dev/socket/recovery", sizeof(addr.sun_path) - 1);
if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
if (connect(sock.get(), (struct sockaddr*)&addr, sizeof(addr)) < 0) {
PLOG(ERROR) << "Couldn't connect to recovery";
return false;
}
// Switch to recovery will not update the boot reason since it does not
// require a reboot.
auto ret = write(sock, &msg_switch_to_recovery, sizeof(msg_switch_to_recovery));
auto ret = write(sock.get(), &msg_switch_to_recovery, sizeof(msg_switch_to_recovery));
if (ret != sizeof(msg_switch_to_recovery)) {
PLOG(ERROR) << "Couldn't write message to switch to recovery";
return false;

View File

@ -82,7 +82,7 @@ static int usb_ffs_write(usb_handle* h, const void* data, int len) {
int orig_len = len;
while (len > 0) {
int write_len = std::min(USB_FFS_BULK_SIZE, len);
int n = write(h->bulk_in, buf, write_len);
int n = write(h->bulk_in.get(), buf, write_len);
if (n < 0) {
D("ERROR: fd = %d, n = %d: %s", h->bulk_in.get(), n, strerror(errno));
return -1;
@ -103,7 +103,7 @@ static int usb_ffs_read(usb_handle* h, void* data, int len, bool allow_partial)
unsigned count = 0;
while (len > 0) {
int read_len = std::min(USB_FFS_BULK_SIZE, len);
int n = read(h->bulk_out, buf, read_len);
int n = read(h->bulk_out.get(), buf, read_len);
if (n < 0) {
D("ERROR: fd = %d, n = %d: %s", h->bulk_out.get(), n, strerror(errno));
return -1;

View File

@ -198,7 +198,7 @@ class MappedDevice final {
~MappedDevice();
int fd() const { return fd_; }
int fd() const { return fd_.get(); }
const std::string& path() const { return path_; }
protected: