[logd] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning. Test: m Bug: 68236239 Change-Id: I15ccb9cfc9967dae4320d9690f5097bc2f7d5bfe
This commit is contained in:
parent
dc8483cc04
commit
c8d09ddceb
11 changed files with 45 additions and 45 deletions
|
@ -173,7 +173,7 @@ class __android_log_event_list : public android_log_event_list {
|
|||
#if defined(_USING_LIBCXX)
|
||||
operator std::string() {
|
||||
if (ret) return std::string("");
|
||||
const char* cp = NULL;
|
||||
const char* cp = nullptr;
|
||||
ssize_t len = android_log_write_list_buffer(ctx, &cp);
|
||||
if (len < 0) ret = len;
|
||||
if (!cp || (len <= 0)) return std::string("");
|
||||
|
|
|
@ -288,9 +288,9 @@ int CommandListener::GetEventTagCmd::runCommand(SocketClient* cli, int argc,
|
|||
uid = AID_ROOT;
|
||||
}
|
||||
|
||||
const char* name = NULL;
|
||||
const char* format = NULL;
|
||||
const char* id = NULL;
|
||||
const char* name = nullptr;
|
||||
const char* format = nullptr;
|
||||
const char* id = nullptr;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
static const char _name[] = "name=";
|
||||
if (!strncmp(argv[i], _name, strlen(_name))) {
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
// reference counts are used to ensure that individual
|
||||
// LogTimeEntry lifetime is managed when not protected.
|
||||
void FlushCommand::runSocketCommand(SocketClient* client) {
|
||||
LogTimeEntry* entry = NULL;
|
||||
LogTimeEntry* entry = nullptr;
|
||||
LastLogTimes& times = mReader.logbuf().mTimes;
|
||||
|
||||
LogTimeEntry::wrlock();
|
||||
|
|
|
@ -171,13 +171,13 @@ void LogAudit::auditParse(const std::string& string, uid_t uid,
|
|||
}
|
||||
|
||||
int LogAudit::logPrint(const char* fmt, ...) {
|
||||
if (fmt == NULL) {
|
||||
if (fmt == nullptr) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
|
||||
char* str = NULL;
|
||||
char* str = nullptr;
|
||||
va_start(args, fmt);
|
||||
int rc = vasprintf(&str, fmt, args);
|
||||
va_end(args);
|
||||
|
@ -228,7 +228,7 @@ int LogAudit::logPrint(const char* fmt, ...) {
|
|||
static char* last_str;
|
||||
static bool last_info;
|
||||
|
||||
if (last_str != NULL) {
|
||||
if (last_str != nullptr) {
|
||||
static const char avc[] = "): avc: ";
|
||||
char* avcl = strstr(last_str, avc);
|
||||
bool skip = false;
|
||||
|
@ -265,10 +265,10 @@ int LogAudit::logPrint(const char* fmt, ...) {
|
|||
|
||||
writev(fdDmesg, iov, arraysize(iov));
|
||||
free(last_str);
|
||||
last_str = NULL;
|
||||
last_str = nullptr;
|
||||
}
|
||||
}
|
||||
if (last_str == NULL) {
|
||||
if (last_str == nullptr) {
|
||||
count = 0;
|
||||
last_str = strdup(str);
|
||||
last_info = info;
|
||||
|
@ -357,7 +357,7 @@ int LogAudit::logPrint(const char* fmt, ...) {
|
|||
static const char comm_str[] = " comm=\"";
|
||||
const char* comm = strstr(str, comm_str);
|
||||
const char* estr = str + strlen(str);
|
||||
const char* commfree = NULL;
|
||||
const char* commfree = nullptr;
|
||||
if (comm) {
|
||||
estr = comm;
|
||||
comm += sizeof(comm_str) - 1;
|
||||
|
|
|
@ -91,7 +91,7 @@ unsigned short LogBufferElement::setDropped(unsigned short value) {
|
|||
|
||||
// caller must own and free character string
|
||||
char* android::tidToName(pid_t tid) {
|
||||
char* retval = NULL;
|
||||
char* retval = nullptr;
|
||||
char buffer[256];
|
||||
snprintf(buffer, sizeof(buffer), "/proc/%u/comm", tid);
|
||||
int fd = open(buffer, O_RDONLY);
|
||||
|
@ -114,7 +114,7 @@ char* android::tidToName(pid_t tid) {
|
|||
char* name = android::pidToName(tid);
|
||||
if (!retval) {
|
||||
retval = name;
|
||||
name = NULL;
|
||||
name = nullptr;
|
||||
}
|
||||
|
||||
// check if comm is truncated, see if cmdline has full representation
|
||||
|
@ -162,15 +162,15 @@ size_t LogBufferElement::populateDroppedMessage(char*& buffer, LogBuffer* parent
|
|||
if (!strncmp(name + 1, commName + 1, len)) {
|
||||
if (commName[len + 1] == '\0') {
|
||||
free(const_cast<char*>(commName));
|
||||
commName = NULL;
|
||||
commName = nullptr;
|
||||
} else {
|
||||
free(const_cast<char*>(name));
|
||||
name = NULL;
|
||||
name = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (name) {
|
||||
char* buf = NULL;
|
||||
char* buf = nullptr;
|
||||
asprintf(&buf, "(%s)", name);
|
||||
if (buf) {
|
||||
free(const_cast<char*>(name));
|
||||
|
@ -178,7 +178,7 @@ size_t LogBufferElement::populateDroppedMessage(char*& buffer, LogBuffer* parent
|
|||
}
|
||||
}
|
||||
if (commName) {
|
||||
char* buf = NULL;
|
||||
char* buf = nullptr;
|
||||
asprintf(&buf, " %s", commName);
|
||||
if (buf) {
|
||||
free(const_cast<char*>(commName));
|
||||
|
@ -187,7 +187,7 @@ size_t LogBufferElement::populateDroppedMessage(char*& buffer, LogBuffer* parent
|
|||
}
|
||||
// identical to below to calculate the buffer size required
|
||||
const char* type = lastSame ? "identical" : "expire";
|
||||
size_t len = snprintf(NULL, 0, format_uid, mUid, name ? name : "",
|
||||
size_t len = snprintf(nullptr, 0, format_uid, mUid, name ? name : "",
|
||||
commName ? commName : "", type, getDropped(),
|
||||
(getDropped() > 1) ? "s" : "");
|
||||
|
||||
|
@ -247,7 +247,7 @@ log_time LogBufferElement::flushTo(SocketClient* reader, LogBuffer* parent,
|
|||
iovec[0].iov_base = &entry;
|
||||
iovec[0].iov_len = entry.hdr_size;
|
||||
|
||||
char* buffer = NULL;
|
||||
char* buffer = nullptr;
|
||||
|
||||
if (mDropped) {
|
||||
entry.len = populateDroppedMessage(buffer, parent, lastSame);
|
||||
|
|
|
@ -44,9 +44,9 @@ static bool groupIsLog(char* buf) {
|
|||
char* ptr;
|
||||
static const char ws[] = " \n";
|
||||
|
||||
for (buf = strtok_r(buf, ws, &ptr); buf; buf = strtok_r(NULL, ws, &ptr)) {
|
||||
for (buf = strtok_r(buf, ws, &ptr); buf; buf = strtok_r(nullptr, ws, &ptr)) {
|
||||
errno = 0;
|
||||
gid_t Gid = strtol(buf, NULL, 10);
|
||||
gid_t Gid = strtol(buf, nullptr, 10);
|
||||
if (errno != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ bool clientHasLogCredentials(uid_t uid, gid_t gid, pid_t pid) {
|
|||
continue;
|
||||
}
|
||||
|
||||
char* line = NULL;
|
||||
char* line = nullptr;
|
||||
size_t len = 0;
|
||||
while (getline(&line, &len, file) > 0) {
|
||||
static const char groups_string[] = "Groups:\t";
|
||||
|
|
|
@ -50,7 +50,7 @@ bool LogListener::onDataAvailable(SocketClient* cli) {
|
|||
|
||||
alignas(4) char control[CMSG_SPACE(sizeof(struct ucred))];
|
||||
struct msghdr hdr = {
|
||||
NULL, 0, &iov, 1, control, sizeof(control), 0,
|
||||
nullptr, 0, &iov, 1, control, sizeof(control), 0,
|
||||
};
|
||||
|
||||
int socket = cli->getSocket();
|
||||
|
@ -66,10 +66,10 @@ bool LogListener::onDataAvailable(SocketClient* cli) {
|
|||
|
||||
buffer[n] = 0;
|
||||
|
||||
struct ucred* cred = NULL;
|
||||
struct ucred* cred = nullptr;
|
||||
|
||||
struct cmsghdr* cmsg = CMSG_FIRSTHDR(&hdr);
|
||||
while (cmsg != NULL) {
|
||||
while (cmsg != nullptr) {
|
||||
if (cmsg->cmsg_level == SOL_SOCKET &&
|
||||
cmsg->cmsg_type == SCM_CREDENTIALS) {
|
||||
cred = (struct ucred*)CMSG_DATA(cmsg);
|
||||
|
@ -79,7 +79,7 @@ bool LogListener::onDataAvailable(SocketClient* cli) {
|
|||
}
|
||||
|
||||
struct ucred fake_cred;
|
||||
if (cred == NULL) {
|
||||
if (cred == nullptr) {
|
||||
cred = &fake_cred;
|
||||
cred->pid = 0;
|
||||
cred->uid = DEFAULT_OVERFLOWUID;
|
||||
|
|
|
@ -56,7 +56,7 @@ size_t sizesTotal() {
|
|||
|
||||
// caller must own and free character string
|
||||
char* pidToName(pid_t pid) {
|
||||
char* retval = NULL;
|
||||
char* retval = nullptr;
|
||||
if (pid == 0) { // special case from auditd/klogd for kernel
|
||||
retval = strdup("logd");
|
||||
} else {
|
||||
|
@ -286,7 +286,7 @@ const char* LogStatistics::uidToName(uid_t uid) const {
|
|||
name = strdup(nameTmp);
|
||||
} else if (fastcmp<strcmp>(name, nameTmp)) {
|
||||
free(const_cast<char*>(name));
|
||||
name = NULL;
|
||||
name = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -872,7 +872,7 @@ const char* LogStatistics::pidToName(pid_t pid) const {
|
|||
pidTable_t& writablePidTable = const_cast<pidTable_t&>(pidTable);
|
||||
const char* name = writablePidTable.add(pid)->second.getName();
|
||||
if (!name) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return strdup(name);
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ bool LogTags::RebuildFileEventLogTags(const char* filename, bool warn) {
|
|||
fd = TEMP_FAILURE_RETRY(open(
|
||||
filename, O_WRONLY | O_TRUNC | O_CLOEXEC | O_NOFOLLOW | O_BINARY));
|
||||
if (fd >= 0) {
|
||||
time_t now = time(NULL);
|
||||
time_t now = time(nullptr);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
char timebuf[20];
|
||||
|
@ -208,7 +208,7 @@ void LogTags::ReadFileEventLogTags(const char* filename, bool warn) {
|
|||
} else if (lineStart) {
|
||||
if (*cp == '#') {
|
||||
/* comment; just scan to end */
|
||||
lineStart = NULL;
|
||||
lineStart = nullptr;
|
||||
} else if (isdigit(*cp)) {
|
||||
unsigned long Tag = strtoul(cp, &cp, 10);
|
||||
if (warn && (Tag > emptyTag)) {
|
||||
|
@ -235,7 +235,7 @@ void LogTags::ReadFileEventLogTags(const char* filename, bool warn) {
|
|||
if (hasAlpha &&
|
||||
((cp >= endp) || (*cp == '#') || isspace(*cp))) {
|
||||
if (Tag > emptyTag) {
|
||||
if (*cp != '\n') lineStart = NULL;
|
||||
if (*cp != '\n') lineStart = nullptr;
|
||||
continue;
|
||||
}
|
||||
while ((cp < endp) && (*cp != '\n') && isspace(*cp))
|
||||
|
@ -245,14 +245,14 @@ void LogTags::ReadFileEventLogTags(const char* filename, bool warn) {
|
|||
while ((cp < endp) && (*cp != '\n')) {
|
||||
if (*cp == '#') {
|
||||
uid = sniffUid(cp, endp);
|
||||
lineStart = NULL;
|
||||
lineStart = nullptr;
|
||||
break;
|
||||
}
|
||||
++cp;
|
||||
}
|
||||
while ((cp > format) && isspace(cp[-1])) {
|
||||
--cp;
|
||||
lineStart = NULL;
|
||||
lineStart = nullptr;
|
||||
}
|
||||
std::string Format(format, cp - format);
|
||||
|
||||
|
@ -263,7 +263,7 @@ void LogTags::ReadFileEventLogTags(const char* filename, bool warn) {
|
|||
android::prdebug("tag name invalid %.*s",
|
||||
(int)(cp - name + 1), name);
|
||||
}
|
||||
lineStart = NULL;
|
||||
lineStart = nullptr;
|
||||
}
|
||||
} else if (!isspace(*cp)) {
|
||||
break;
|
||||
|
@ -364,7 +364,7 @@ const char* LogTags::tagToName(uint32_t tag) const {
|
|||
android::RWLock::AutoRLock readLock(const_cast<android::RWLock&>(rwlock));
|
||||
|
||||
it = tag2name.find(tag);
|
||||
if ((it == tag2name.end()) || (it->second.length() == 0)) return NULL;
|
||||
if ((it == tag2name.end()) || (it->second.length() == 0)) return nullptr;
|
||||
|
||||
return it->second.c_str();
|
||||
}
|
||||
|
@ -383,7 +383,7 @@ const char* LogTags::tagToName(uint32_t tag) const {
|
|||
const char* android::tagToName(uint32_t tag) {
|
||||
LogTags* me = logtags;
|
||||
|
||||
if (!me) return NULL;
|
||||
if (!me) return nullptr;
|
||||
me->WritePmsgEventLogTags(tag);
|
||||
return me->tagToName(tag);
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ const char* LogTags::tagToFormat(uint32_t tag) const {
|
|||
android::RWLock::AutoRLock readLock(const_cast<android::RWLock&>(rwlock));
|
||||
|
||||
iform = tag2format.find(tag);
|
||||
if (iform == tag2format.end()) return NULL;
|
||||
if (iform == tag2format.end()) return nullptr;
|
||||
|
||||
return iform->second.c_str();
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ uint32_t LogTags::nameToTag_locked(const std::string& name, const char* format,
|
|||
bool& unique) {
|
||||
key2tag_const_iterator ik;
|
||||
|
||||
bool write = format != NULL;
|
||||
bool write = format != nullptr;
|
||||
unique = write;
|
||||
|
||||
if (!write) {
|
||||
|
@ -679,7 +679,7 @@ void LogTags::WritePersistEventLogTags(uint32_t tag, uid_t uid,
|
|||
// are in readonly mode.
|
||||
uint32_t LogTags::nameToTag(uid_t uid, const char* name, const char* format) {
|
||||
std::string Name = std::string(name);
|
||||
bool write = format != NULL;
|
||||
bool write = format != nullptr;
|
||||
bool updateUid = uid != AID_ROOT;
|
||||
bool updateFormat = format && *format;
|
||||
bool unique;
|
||||
|
@ -848,7 +848,7 @@ std::string LogTags::formatGetEventTag(uid_t uid, const char* name,
|
|||
|
||||
if (!list) {
|
||||
// switch to read entry only if format == "*"
|
||||
if (format && (format[0] == '*') && !format[1]) format = NULL;
|
||||
if (format && (format[0] == '*') && !format[1]) format = nullptr;
|
||||
|
||||
// WAI: for null format, only works for a single entry, we can have
|
||||
// multiple entries, one for each format, so we find first entry
|
||||
|
|
|
@ -87,14 +87,14 @@ class LogTags {
|
|||
bool RebuildFileEventLogTags(const char* filename, bool warn = true);
|
||||
|
||||
void AddEventLogTags(uint32_t tag, uid_t uid, const std::string& Name,
|
||||
const std::string& Format, const char* source = NULL,
|
||||
const std::string& Format, const char* source = nullptr,
|
||||
bool warn = false);
|
||||
|
||||
void WriteDynamicEventLogTags(uint32_t tag, uid_t uid);
|
||||
void WriteDebugEventLogTags(uint32_t tag, uid_t uid);
|
||||
// push tag details to persistent storage
|
||||
void WritePersistEventLogTags(uint32_t tag, uid_t uid = AID_ROOT,
|
||||
const char* source = NULL);
|
||||
const char* source = nullptr);
|
||||
|
||||
static const uint32_t emptyTag = uint32_t(-1);
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ std::string Prune::format() {
|
|||
}
|
||||
|
||||
PruneList::PruneList() {
|
||||
init(NULL);
|
||||
init(nullptr);
|
||||
}
|
||||
|
||||
PruneList::~PruneList() {
|
||||
|
@ -79,7 +79,7 @@ int PruneList::init(const char* str) {
|
|||
// default here means take ro.logd.filter, persist.logd.filter then
|
||||
// internal default in that order.
|
||||
if (str && !strcmp(str, _default)) {
|
||||
str = NULL;
|
||||
str = nullptr;
|
||||
}
|
||||
static const char _disable[] = "disable";
|
||||
if (str && !strcmp(str, _disable)) {
|
||||
|
|
Loading…
Reference in a new issue