summaryrefslogtreecommitdiffstats
path: root/logd/LogWhiteBlackList.cpp
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2015-08-20 10:01:44 -0700
committerMark Salyzyn <salyzyn@google.com>2015-08-20 10:32:16 -0700
commit73160acc5cb5236b30327569e6b51dbfe73e4a0f (patch)
tree8c8fcba4ddf27d22664913f08f38fe24a08f84eb /logd/LogWhiteBlackList.cpp
parentdecbcd9c418a4d076965971e74fd51fab497414b (diff)
downloadcore-73160acc5cb5236b30327569e6b51dbfe73e4a0f.tar.gz
core-73160acc5cb5236b30327569e6b51dbfe73e4a0f.tar.bz2
core-73160acc5cb5236b30327569e6b51dbfe73e4a0f.zip
logd: switch asprintf to std::string
Bug: 23350706 Change-Id: I715cdd4563a09de3680081947a3439f0cac623be
Diffstat (limited to 'logd/LogWhiteBlackList.cpp')
-rw-r--r--logd/LogWhiteBlackList.cpp43
1 files changed, 13 insertions, 30 deletions
diff --git a/logd/LogWhiteBlackList.cpp b/logd/LogWhiteBlackList.cpp
index 0406bf3d0..ad005ec33 100644
--- a/logd/LogWhiteBlackList.cpp
+++ b/logd/LogWhiteBlackList.cpp
@@ -16,8 +16,6 @@
#include <ctype.h>
-#include <string>
-
#include <base/stringprintf.h>
#include "LogWhiteBlackList.h"
@@ -37,18 +35,18 @@ int Prune::cmp(uid_t uid, pid_t pid) const {
return uid - mUid;
}
-void Prune::format(char **strp) {
+std::string Prune::format() {
if (mUid != uid_all) {
if (mPid != pid_all) {
- asprintf(strp, "%u/%u", mUid, mPid);
- } else {
- asprintf(strp, "%u", mUid);
+ return android::base::StringPrintf("%u/%u", mUid, mPid);
}
- } else if (mPid != pid_all) {
- asprintf(strp, "/%u", mPid);
- } else { // NB: mPid == pid_all can not happen if mUid == uid_all
- asprintf(strp, "/");
+ return android::base::StringPrintf("%u", mUid);
+ }
+ if (mPid != pid_all) {
+ return android::base::StringPrintf("/%u", mPid);
}
+ // NB: mPid == pid_all can not happen if mUid == uid_all
+ return std::string("/");
}
PruneList::PruneList() : mWorstUidEnabled(true) {
@@ -64,7 +62,7 @@ PruneList::~PruneList() {
}
}
-int PruneList::init(char *str) {
+int PruneList::init(const char *str) {
mWorstUidEnabled = true;
PruneCollection::iterator it;
for (it = mNice.begin(); it != mNice.end();) {
@@ -169,12 +167,7 @@ int PruneList::init(char *str) {
return 0;
}
-void PruneList::format(char **strp) {
- if (*strp) {
- free(*strp);
- *strp = NULL;
- }
-
+std::string PruneList::format() {
static const char nice_format[] = " %s";
const char *fmt = nice_format + 1;
@@ -188,28 +181,18 @@ void PruneList::format(char **strp) {
PruneCollection::iterator it;
for (it = mNice.begin(); it != mNice.end(); ++it) {
- char *a = NULL;
- (*it).format(&a);
-
- string += android::base::StringPrintf(fmt, a);
+ string += android::base::StringPrintf(fmt, (*it).format().c_str());
fmt = nice_format;
-
- free(a);
}
static const char naughty_format[] = " ~%s";
fmt = naughty_format + (*fmt != ' ');
for (it = mNaughty.begin(); it != mNaughty.end(); ++it) {
- char *a = NULL;
- (*it).format(&a);
-
- string += android::base::StringPrintf(fmt, a);
+ string += android::base::StringPrintf(fmt, (*it).format().c_str());
fmt = naughty_format;
-
- free(a);
}
- *strp = strdup(string.c_str());
+ return string;
}
// ToDo: Lists are in sorted order, Prune->cmp() returns + or -