Removes old-style casts found by -Wold-style-cast
Bug: 79494229
Test: Build and boot omr1
Change-Id: I55149295fb36cc8a841cc0c4c09a7c5a129744fe
diff --git a/common/libs/fs/shared_fd.cpp b/common/libs/fs/shared_fd.cpp
index 46de0ba..690507c 100644
--- a/common/libs/fs/shared_fd.cpp
+++ b/common/libs/fs/shared_fd.cpp
@@ -274,7 +274,7 @@
if (!rval->IsOpen()) {
return rval;
}
- if (rval->Connect((struct sockaddr*)&addr, addrlen) == -1) {
+ if (rval->Connect(reinterpret_cast<sockaddr*>(&addr), addrlen) == -1) {
LOG(ERROR) << "Connect failed; name=" << name << ": " << rval->StrError();
return SharedFD(
std::shared_ptr<FileInstance>(new FileInstance(-1, rval->GetErrno())));
@@ -316,7 +316,7 @@
return SharedFD(
std::shared_ptr<FileInstance>(new FileInstance(-1, rval->GetErrno())));
}
- if(rval->Bind((struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ if(rval->Bind(reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) < 0) {
LOG(ERROR) << "Bind failed " << rval->StrError();
return SharedFD(
std::shared_ptr<FileInstance>(new FileInstance(-1, rval->GetErrno())));
@@ -351,7 +351,7 @@
return SharedFD(
std::shared_ptr<FileInstance>(new FileInstance(-1, rval->GetErrno())));
}
- if (rval->Bind((struct sockaddr*)&addr, addrlen) == -1) {
+ if (rval->Bind(reinterpret_cast<sockaddr*>(&addr), addrlen) == -1) {
LOG(ERROR) << "Bind failed; name=" << name << ": " << rval->StrError();
return SharedFD(
std::shared_ptr<FileInstance>(new FileInstance(-1, rval->GetErrno())));
diff --git a/common/libs/net/netlink_client.cpp b/common/libs/net/netlink_client.cpp
index 884daca..96eb4a9 100644
--- a/common/libs/net/netlink_client.cpp
+++ b/common/libs/net/netlink_client.cpp
@@ -63,10 +63,12 @@
return false;
}
- len = (uint32_t)result;
+ len = static_cast<uint32_t>(result);
LOG(INFO) << "Received netlink response (" << len << " bytes)";
- for (nh = (struct nlmsghdr*)buf; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len)) {
+ for (nh = reinterpret_cast<nlmsghdr*>(buf);
+ NLMSG_OK(nh, len);
+ nh = NLMSG_NEXT(nh, len)) {
if (nh->nlmsg_seq != seq_no) {
// This really shouldn't happen. If we see this, it means somebody is
// issuing netlink requests using the same socket as us, and ignoring
@@ -133,7 +135,7 @@
address_.nl_family = AF_NETLINK;
address_.nl_groups = 0;
- netlink_fd_->Bind((struct sockaddr*)&address_, sizeof(address_));
+ netlink_fd_->Bind(reinterpret_cast<sockaddr*>(&address_), sizeof(address_));
return true;
}
diff --git a/common/libs/time/monotonic_time.h b/common/libs/time/monotonic_time.h
index 1d61ab4..8f5de13 100644
--- a/common/libs/time/monotonic_time.h
+++ b/common/libs/time/monotonic_time.h
@@ -58,7 +58,7 @@
// Nanoseconds must be in [0, 10^9) and so all are less
// then 2^30. Even multiplied by the largest uint32
// this will fit in a 64-bit int without overflow.
- int64_t tv_nsec = (int64_t)ts_.tv_nsec * factor;
+ int64_t tv_nsec = static_cast<int64_t>(ts_.tv_nsec) * factor;
rval.ts_.tv_sec += (tv_nsec / kNanosecondsPerSecond);
rval.ts_.tv_nsec = tv_nsec % kNanosecondsPerSecond;
return rval;
diff --git a/host/commands/launch/ril_region_handler.cc b/host/commands/launch/ril_region_handler.cc
index 853c418..e122e29 100644
--- a/host/commands/launch/ril_region_handler.cc
+++ b/host/commands/launch/ril_region_handler.cc
@@ -66,14 +66,14 @@
private:
bool GetBroadcastAddr(const std::string& interface) {
- struct ifaddrs *ifap, *ifa;
- struct sockaddr_in *sa;
- char *addr;
+ struct ifaddrs *ifap{}, *ifa{};
+ struct sockaddr_in *sa{};
+ char *addr{};
getifaddrs (&ifap);
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr && ifa->ifa_addr->sa_family==AF_INET) {
if (strcmp(ifa->ifa_name, interface.c_str())) continue;
- sa = (struct sockaddr_in *) ifa->ifa_ifu.ifu_broadaddr;
+ sa = reinterpret_cast<sockaddr_in*>(ifa->ifa_ifu.ifu_broadaddr);
addr = inet_ntoa(sa->sin_addr);
this->ril_broadcast = strtok(addr, "\n");
}
@@ -102,7 +102,7 @@
xmlNode* element = xmlDocGetRootElement(doc.get());
element = element->xmlChildrenNode;
while (element) {
- if (strcmp((char*)element->name, "ip") == 0) {
+ if (strcmp(reinterpret_cast<const char*>(element->name), "ip") == 0) {
return ProcessIpNode(element);
}
element = element->next;
@@ -113,10 +113,12 @@
bool ParseIpAttributes(xmlNode* ip_node) {
// The gateway is the host ip address
- this->ril_gateway = (char*)xmlGetProp(ip_node, (xmlChar*)"address");
+ this->ril_gateway = reinterpret_cast<const char*>(
+ xmlGetProp(ip_node, reinterpret_cast<const xmlChar*>("address")));
// The prefix length need to be obtained from the network mask
- char* netmask = (char*)xmlGetProp(ip_node, (xmlChar*)"netmask");
+ auto* netmask = reinterpret_cast<const char*>(
+ xmlGetProp(ip_node, reinterpret_cast<const xmlChar*>("netmask")));
int byte1, byte2, byte3, byte4;
sscanf(netmask, "%d.%d.%d.%d", &byte1, &byte2, &byte3, &byte4);
this->ril_prefixlen = 0;
@@ -130,8 +132,9 @@
bool ProcessDhcpNode(xmlNode* dhcp_node) {
xmlNode* child = dhcp_node->xmlChildrenNode;
while (child) {
- if (strcmp((char*)child->name, "range") == 0) {
- this->ril_ipaddr = (char*)xmlGetProp(child, (xmlChar*)"start");
+ if (strcmp(reinterpret_cast<const char*>(child->name), "range") == 0) {
+ this->ril_ipaddr = reinterpret_cast<const char*>(
+ xmlGetProp(child, reinterpret_cast<const xmlChar*>("start")));
return true;
}
child = child->next;
@@ -144,7 +147,7 @@
ParseIpAttributes(ip_node);
xmlNode* child = ip_node->xmlChildrenNode;
while (child) {
- if (strcmp((char*)child->name, "dhcp") == 0) {
+ if (strcmp(reinterpret_cast<const char*>(child->name), "dhcp") == 0) {
return ProcessDhcpNode(child);
}
child = child->next;
diff --git a/host/libs/config/guest_config.cpp b/host/libs/config/guest_config.cpp
index b1b4d08..a812966 100644
--- a/host/libs/config/guest_config.cpp
+++ b/host/libs/config/guest_config.cpp
@@ -323,7 +323,7 @@
int tgt_len;
xmlDocDumpFormatMemoryEnc(xml.get(), &tgt, &tgt_len, "utf-8", true);
- std::string out((const char*)(tgt), tgt_len);
+ std::string out(reinterpret_cast<const char*>(tgt), tgt_len);
xmlFree(tgt);
return out;
}