summaryrefslogtreecommitdiff
path: root/libs/binder/RpcSession.cpp
diff options
context:
space:
mode:
author Jiyong Park <jiyong@google.com> 2022-03-08 16:56:13 +0900
committer Jiyong Park <jiyong@google.com> 2022-03-09 19:08:34 +0900
commit5970d0a5dc54ec30b3434dd6a23305233698c9c7 (patch)
tree64b6df23b979c704e8be547cf49df74f5d4a6105 /libs/binder/RpcSession.cpp
parent1caffe38d6f5a1e53db6fdc5075642be90eca85e (diff)
Fix or suppress tidy warnings-as-errors.
Use std::map instead of KeyedVector (deprecated) in order to avoid unnecessary (and implicit) initialization of the value type. KeyedVector does it even when only the key is neeed (e.g. indexOfKey). std::map doesn't have such a problem. Bug: 222775179 Test: unset WITH_TIDY; CLANG_ANALYZER_CHECKS=1 make -k tidy-frameworks-native-libs-binder Change-Id: I548fc96a34bac9c7135e206983150948dbca57d4
Diffstat (limited to 'libs/binder/RpcSession.cpp')
-rw-r--r--libs/binder/RpcSession.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp
index b84395e7cb..e79cb86ffa 100644
--- a/libs/binder/RpcSession.cpp
+++ b/libs/binder/RpcSession.cpp
@@ -152,8 +152,13 @@ status_t RpcSession::setupInetClient(const char* addr, unsigned int port) {
}
status_t RpcSession::setupPreconnectedClient(unique_fd fd, std::function<unique_fd()>&& request) {
- return setupClient([&](const std::vector<uint8_t>& sessionId, bool incoming) -> status_t {
- // std::move'd from fd becomes -1 (!ok())
+ // Why passing raw fd? When fd is passed as reference, Clang analyzer sees that the variable
+ // `fd` is a moved-from object. To work-around the issue, unwrap the raw fd from the outer `fd`,
+ // pass the raw fd by value to the lambda, and then finally wrap it in unique_fd inside the
+ // lambda.
+ return setupClient([&, raw = fd.release()](const std::vector<uint8_t>& sessionId,
+ bool incoming) -> status_t {
+ unique_fd fd(raw);
if (!fd.ok()) {
fd = request();
if (!fd.ok()) return BAD_VALUE;