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
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 @@
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