binder_test: Avoid extra std::string copies
When a function argument is a const std::string reference, it's
inefficient to pass a std::string::c_str(). We're not particularly
concerned about the performance of this test, but by fixing up
this issue, it makes using static analysis to find this issue in
our code base less noisy.
Test: TreeHugger
Change-Id: I69fefcaa480ca6b0106e3362821acd73052668b9
diff --git a/tests/binder_test.cpp b/tests/binder_test.cpp
index bb569e9..ad0dfef 100644
--- a/tests/binder_test.cpp
+++ b/tests/binder_test.cpp
@@ -1222,8 +1222,8 @@
std::string uidRule = StringPrintf("owner UID match %u", uid);
std::string perUidChain = StringPrintf("st_clear_caught_%u", uid);
for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) {
- EXPECT_FALSE(iptablesRuleExists(binary, STRICT_OUTPUT, uidRule.c_str()));
- EXPECT_FALSE(iptablesRuleExists(binary, STRICT_CLEAR_CAUGHT, uidRule.c_str()));
+ EXPECT_FALSE(iptablesRuleExists(binary, STRICT_OUTPUT, uidRule));
+ EXPECT_FALSE(iptablesRuleExists(binary, STRICT_CLEAR_CAUGHT, uidRule));
EXPECT_EQ(0, iptablesRuleLineLength(binary, perUidChain.c_str()));
}
}
@@ -1233,8 +1233,8 @@
std::string uidRule = StringPrintf("owner UID match %u", uid);
std::string perUidChain = StringPrintf("st_clear_caught_%u", uid);
for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) {
- EXPECT_TRUE(iptablesRuleExists(binary, STRICT_OUTPUT, uidRule.c_str()));
- EXPECT_TRUE(iptablesRuleExists(binary, STRICT_CLEAR_CAUGHT, uidRule.c_str()));
+ EXPECT_TRUE(iptablesRuleExists(binary, STRICT_OUTPUT, uidRule));
+ EXPECT_TRUE(iptablesRuleExists(binary, STRICT_CLEAR_CAUGHT, uidRule));
EXPECT_TRUE(iptablesRuleExists(binary, perUidChain.c_str(), logRule));
}
}
@@ -1244,8 +1244,8 @@
std::string uidRule = StringPrintf("owner UID match %u", uid);
std::string perUidChain = StringPrintf("st_clear_caught_%u", uid);
for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) {
- EXPECT_TRUE(iptablesRuleExists(binary, STRICT_OUTPUT, uidRule.c_str()));
- EXPECT_TRUE(iptablesRuleExists(binary, STRICT_CLEAR_CAUGHT, uidRule.c_str()));
+ EXPECT_TRUE(iptablesRuleExists(binary, STRICT_OUTPUT, uidRule));
+ EXPECT_TRUE(iptablesRuleExists(binary, STRICT_CLEAR_CAUGHT, uidRule));
EXPECT_TRUE(iptablesRuleExists(binary, perUidChain.c_str(), rejectRule));
}
}
@@ -1297,7 +1297,7 @@
std::string cmd = StringPrintf("ps -Af | grep '[0-9] %s'", processName.c_str());
std::vector<std::string> result;
for (uint32_t run = 1;;) {
- result = runCommand(cmd.c_str());
+ result = runCommand(cmd);
if (result.size() || ++run > maxTries) {
break;
}