summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Żenczykowski <maze@google.com>2020-04-24 16:40:41 +0000
committerMaciej Zenczykowski <maze@google.com>2020-04-24 17:16:36 +0000
commiteaa7b9eb3f341410e2e637f90217629d972b32f6 (patch)
tree206a9ee3254ca45160b6db68fb6ac12cd10391bb
parentc65b351176ff0cc00cf1ba8a1cad318473a5d055 (diff)
downloadbpf-eaa7b9eb3f341410e2e637f90217629d972b32f6.tar.gz
BpfMap.h - fix cert-oop54-cpp compiler warning
Fixes: system/bpf/libbpf_android/include/bpf/BpfMap.h:132:10: warning: operator=() does not handle self-assignment properly [cert-oop54-cpp] void operator=(const BpfMap<Key, Value>& other) { ^ Matches the self-assignment check from https://clang.llvm.org/extra/clang-tidy/checks/bugprone-unhandled-self-assignment.html This isn't needed here, since the code was already correct, but it does prevent a pointless newfd = dup(fd); close(fd); sequence. Test: builds Bug: 153035880 Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: Ia57f95d4ab180783c97db7e6f8d929f822c8958d Merged-In: Ia57f95d4ab180783c97db7e6f8d929f822c8958d
-rw-r--r--libbpf_android/include/bpf/BpfMap.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/libbpf_android/include/bpf/BpfMap.h b/libbpf_android/include/bpf/BpfMap.h
index 8c35931..c92f989 100644
--- a/libbpf_android/include/bpf/BpfMap.h
+++ b/libbpf_android/include/bpf/BpfMap.h
@@ -129,8 +129,9 @@ class BpfMap {
const base::unique_fd& getMap() const { return mMapFd; };
// Copy assignment operator
- void operator=(const BpfMap<Key, Value>& other) {
- mMapFd.reset(fcntl(other.mMapFd.get(), F_DUPFD_CLOEXEC, 0));
+ BpfMap<Key, Value>& operator=(const BpfMap<Key, Value>& other) {
+ if (this != &other) mMapFd.reset(fcntl(other.mMapFd.get(), F_DUPFD_CLOEXEC, 0));
+ return *this;
}
// Move constructor