From 94c35d65cef74d6b330410be49dff1f18928f0cc Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Thu, 28 Mar 2019 20:48:02 +0900 Subject: Fix incorrect error checking on unique_fd The expression "!fd" calls the implicit conversion to int, but comparing the raw fd against 0 won't work, since open() and other POSIX calls returning file descriptors use -1 to signal an error. Test: m verity_verifier Change-Id: Ib117de62ff46c8d3389db54875bfa269fd539b51 --- verity/verity_verifier.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/verity/verity_verifier.cpp b/verity/verity_verifier.cpp index 036e85be..e770708f 100644 --- a/verity/verity_verifier.cpp +++ b/verity/verity_verifier.cpp @@ -80,7 +80,7 @@ int main(int argc, char* argv[]) { // Get the raw image. android::base::unique_fd fd(open(argv[1], O_RDONLY)); - if (!fd) { + if (fd == -1) { fprintf(stderr, "failed to open %s: %s\n", argv[1], strerror(errno)); return 1; } -- cgit v1.2.3