From ebe293ab54472f5adf6189edbaa1e73939320b66 Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Thu, 28 Mar 2019 15:24:30 +0900 Subject: [PATCH] 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 vold Change-Id: I0847c276f39cb9dd09c7ffb96951276113418fc8 --- Checkpoint.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Checkpoint.cpp b/Checkpoint.cpp index e060230..8605b6a 100644 --- a/Checkpoint.cpp +++ b/Checkpoint.cpp @@ -330,7 +330,7 @@ Status cp_prepareCheckpoint() { if (fstab_rec->fs_mgr_flags.checkpoint_blk) { android::base::unique_fd fd( TEMP_FAILURE_RETRY(open(mount_rec.mount_point.c_str(), O_RDONLY | O_CLOEXEC))); - if (!fd) { + if (fd == -1) { PLOG(ERROR) << "Failed to open mount point" << mount_rec.mount_point; continue; }