From 7c706baedbbb0d739c9a231be36b0430faa2fbe6 Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Wed, 4 Sep 2019 13:46:50 -0700 Subject: [PATCH] Improve codegen slightly when doing FD validity checks See https://gcc.godbolt.org/z/hGUZIk Test: inspection Bug: 140506797 Change-Id: I6fe87b16e18c93b7fc3ca28edbbc68c245e7e5e5 --- base/include/android-base/unique_fd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/include/android-base/unique_fd.h b/base/include/android-base/unique_fd.h index 6e11b4ee7..1605daf71 100644 --- a/base/include/android-base/unique_fd.h +++ b/base/include/android-base/unique_fd.h @@ -120,7 +120,7 @@ class unique_fd_impl final { // Catch bogus error checks (i.e.: "!fd" instead of "fd != -1"). bool operator!() const = delete; - bool ok() const { return get() != -1; } + bool ok() const { return get() >= 0; } int release() __attribute__((warn_unused_result)) { tag(fd_, this, nullptr);