Resolv: Enable clang-tidy and fix all warnings
Bug: 140539187
Test: built, flashed, booted, check warnings
Test: atest
Change-Id: Ifa56f5536c6efb49ea3c74cb011f7c2fd952db32
diff --git a/Android.bp b/Android.bp
index 6d566d6..b8e7b5a 100644
--- a/Android.bp
+++ b/Android.bp
@@ -94,8 +94,7 @@
"libnetd_client_headers",
],
export_include_dirs: ["include"],
- // TODO: pie in the sky: make this code clang-tidy clean
- tidy: false,
+
product_variables: {
debuggable: {
cppflags: [
diff --git a/ResolverController.cpp b/ResolverController.cpp
index a53d05a..3d5b10c 100644
--- a/ResolverController.cpp
+++ b/ResolverController.cpp
@@ -37,7 +37,6 @@
#include "netd_resolv/stats.h"
#include "resolv_cache.h"
-using namespace std::placeholders;
using aidl::android::net::ResolverParamsParcel;
namespace android {
@@ -179,7 +178,7 @@
[](uint32_t netId, uint32_t uid, android_net_context* netcontext) {
gResNetdCallbacks.get_network_context(netId, uid, netcontext);
},
- std::bind(sendNat64PrefixEvent, _1)) {}
+ std::bind(sendNat64PrefixEvent, std::placeholders::_1)) {}
void ResolverController::destroyNetworkCache(unsigned netId) {
LOG(VERBOSE) << __func__ << ": netId = " << netId;
diff --git a/gethnamaddr.cpp b/gethnamaddr.cpp
index 97236f9..fb41f18 100644
--- a/gethnamaddr.cpp
+++ b/gethnamaddr.cpp
@@ -110,8 +110,8 @@
static struct hostent* getanswer(const querybuf*, int, const char*, int, res_state, struct hostent*,
char*, size_t, int*);
static void convert_v4v6_hostent(struct hostent* hp, char** bpp, char* ep,
- std::function<void(struct hostent* hp)> mapping_param,
- std::function<void(char* src, char* dst)> mapping_addr);
+ const std::function<void(struct hostent* hp)>& mapping_param,
+ const std::function<void(char* src, char* dst)>& mapping_addr);
static void pad_v4v6_hostent(struct hostent* hp, char** bpp, char* ep);
static void addrsort(char**, int, res_state);
@@ -656,10 +656,9 @@
return NULL;
}
-
static void convert_v4v6_hostent(struct hostent* hp, char** bpp, char* ep,
- std::function<void(struct hostent* hp)> map_param,
- std::function<void(char* src, char* dst)> map_addr) {
+ const std::function<void(struct hostent* hp)>& map_param,
+ const std::function<void(char* src, char* dst)>& map_addr) {
_DIAGASSERT(hp != NULL);
_DIAGASSERT(bpp != NULL);
_DIAGASSERT(ep != NULL);
diff --git a/res_cache.cpp b/res_cache.cpp
index ceaaf04..5dc2c82 100644
--- a/res_cache.cpp
+++ b/res_cache.cpp
@@ -906,7 +906,7 @@
// std::unique_lock.
class SCOPED_CAPABILITY ScopedAssumeLocked {
public:
- ScopedAssumeLocked(std::mutex& mutex) ACQUIRE(mutex) {}
+ explicit ScopedAssumeLocked(std::mutex& mutex) ACQUIRE(mutex) {}
~ScopedAssumeLocked() RELEASE() {}
};
diff --git a/res_send.cpp b/res_send.cpp
index fa3371f..8b416b0 100644
--- a/res_send.cpp
+++ b/res_send.cpp
@@ -113,8 +113,24 @@
#include "stats.pb.h"
// TODO: use the namespace something like android::netd_resolv for libnetd_resolv
-using namespace android::net;
+using android::net::CacheStatus;
+using android::net::DnsQueryEvent;
+using android::net::DnsTlsDispatcher;
+using android::net::DnsTlsTransport;
+using android::net::gPrivateDnsConfiguration;
+using android::net::IpVersion;
+using android::net::IV_IPV4;
+using android::net::IV_IPV6;
+using android::net::IV_UNKNOWN;
using android::net::NetworkDnsEventReported;
+using android::net::NS_T_INVALID;
+using android::net::NsRcode;
+using android::net::NsType;
+using android::net::PrivateDnsMode;
+using android::net::PrivateDnsModes;
+using android::net::PrivateDnsStatus;
+using android::net::PROTO_TCP;
+using android::net::PROTO_UDP;
using android::netdutils::Slice;
using android::netdutils::Stopwatch;
@@ -285,7 +301,7 @@
* author:
* paul vixie, 29may94
*/
-static int res_ourserver_p(const res_state statp, const sockaddr* sa) {
+static int res_ourserver_p(res_state statp, const sockaddr* sa) {
const sockaddr_in *inp, *srv;
const sockaddr_in6 *in6p, *srv6;
int ns;
@@ -698,7 +714,7 @@
}
}
-static struct timespec get_timeout(const res_state statp, const res_params* params, const int ns) {
+static struct timespec get_timeout(res_state statp, const res_params* params, const int ns) {
int msec;
// Legacy algorithm which scales the timeout by nameserver number.
// For instance, with 4 nameservers: 5s, 2.5s, 5s, 10s