OSDN Git Service

Fix incorrect error checking on unique_fd
authorBernie Innocenti <codewiz@google.com>
Thu, 28 Mar 2019 11:48:02 +0000 (20:48 +0900)
committerBernie Innocenti <codewiz@google.com>
Thu, 28 Mar 2019 11:48:02 +0000 (20:48 +0900)
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

index 036e85b..e770708 100644 (file)
@@ -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;
   }