From 8bd6f455d261fa62a20321a426723c491903a82e Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Thu, 28 Mar 2019 15:48:08 +0900 Subject: Fix bogus error checking on unique_fd The expression "!fd" calls the implicit conversion to int, but comparing the raw fd against 0 does not work, since open() and other POSIX calls returning a file descriptor use -1 to signal an error. Test: m recovery Change-Id: I0847c276f39cb9dd09c7ffb96951276113418fc8 --- applypatch/applypatch.cpp | 2 +- fuse_sideload/fuse_sideload.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index f9383ddeb..90d8e8604 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -76,7 +76,7 @@ static bool ReadPartitionToBuffer(const Partition& partition, FileContents* out, } android::base::unique_fd dev(open(partition.name.c_str(), O_RDONLY)); - if (!dev) { + if (dev == -1) { PLOG(ERROR) << "Failed to open eMMC partition \"" << partition << "\""; } else { std::vector buffer(partition.size); diff --git a/fuse_sideload/fuse_sideload.cpp b/fuse_sideload/fuse_sideload.cpp index b5b6ac15e..3d9480309 100644 --- a/fuse_sideload/fuse_sideload.cpp +++ b/fuse_sideload/fuse_sideload.cpp @@ -392,7 +392,7 @@ int run_fuse_sideload(std::unique_ptr&& provider, const char* } fd.ffd.reset(open("/dev/fuse", O_RDWR)); - if (!fd.ffd) { + if (fd.ffd == -1) { perror("open /dev/fuse"); result = -1; goto done; -- cgit v1.2.3