Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a989cf5 authored by Yi Kong's avatar Yi Kong Committed by Gerrit Code Review
Browse files

Merge "[logd] Modernize codebase by replacing NULL with nullptr"

parents dc8483cc c8d09ddc
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -173,7 +173,7 @@ class __android_log_event_list : public android_log_event_list {
#if defined(_USING_LIBCXX)
#if defined(_USING_LIBCXX)
  operator std::string() {
  operator std::string() {
    if (ret) return 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);
    ssize_t len = android_log_write_list_buffer(ctx, &cp);
    if (len < 0) ret = len;
    if (len < 0) ret = len;
    if (!cp || (len <= 0)) return std::string("");
    if (!cp || (len <= 0)) return std::string("");
+3 −3
Original line number Original line Diff line number Diff line
@@ -288,9 +288,9 @@ int CommandListener::GetEventTagCmd::runCommand(SocketClient* cli, int argc,
        uid = AID_ROOT;
        uid = AID_ROOT;
    }
    }


    const char* name = NULL;
    const char* name = nullptr;
    const char* format = NULL;
    const char* format = nullptr;
    const char* id = NULL;
    const char* id = nullptr;
    for (int i = 1; i < argc; ++i) {
    for (int i = 1; i < argc; ++i) {
        static const char _name[] = "name=";
        static const char _name[] = "name=";
        if (!strncmp(argv[i], _name, strlen(_name))) {
        if (!strncmp(argv[i], _name, strlen(_name))) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -36,7 +36,7 @@
// reference counts are used to ensure that individual
// reference counts are used to ensure that individual
// LogTimeEntry lifetime is managed when not protected.
// LogTimeEntry lifetime is managed when not protected.
void FlushCommand::runSocketCommand(SocketClient* client) {
void FlushCommand::runSocketCommand(SocketClient* client) {
    LogTimeEntry* entry = NULL;
    LogTimeEntry* entry = nullptr;
    LastLogTimes& times = mReader.logbuf().mTimes;
    LastLogTimes& times = mReader.logbuf().mTimes;


    LogTimeEntry::wrlock();
    LogTimeEntry::wrlock();
+6 −6
Original line number Original line Diff line number Diff line
@@ -171,13 +171,13 @@ void LogAudit::auditParse(const std::string& string, uid_t uid,
}
}


int LogAudit::logPrint(const char* fmt, ...) {
int LogAudit::logPrint(const char* fmt, ...) {
    if (fmt == NULL) {
    if (fmt == nullptr) {
        return -EINVAL;
        return -EINVAL;
    }
    }


    va_list args;
    va_list args;


    char* str = NULL;
    char* str = nullptr;
    va_start(args, fmt);
    va_start(args, fmt);
    int rc = vasprintf(&str, fmt, args);
    int rc = vasprintf(&str, fmt, args);
    va_end(args);
    va_end(args);
@@ -228,7 +228,7 @@ int LogAudit::logPrint(const char* fmt, ...) {
        static char* last_str;
        static char* last_str;
        static bool last_info;
        static bool last_info;


        if (last_str != NULL) {
        if (last_str != nullptr) {
            static const char avc[] = "): avc: ";
            static const char avc[] = "): avc: ";
            char* avcl = strstr(last_str, avc);
            char* avcl = strstr(last_str, avc);
            bool skip = false;
            bool skip = false;
@@ -265,10 +265,10 @@ int LogAudit::logPrint(const char* fmt, ...) {


                writev(fdDmesg, iov, arraysize(iov));
                writev(fdDmesg, iov, arraysize(iov));
                free(last_str);
                free(last_str);
                last_str = NULL;
                last_str = nullptr;
            }
            }
        }
        }
        if (last_str == NULL) {
        if (last_str == nullptr) {
            count = 0;
            count = 0;
            last_str = strdup(str);
            last_str = strdup(str);
            last_info = info;
            last_info = info;
@@ -357,7 +357,7 @@ int LogAudit::logPrint(const char* fmt, ...) {
    static const char comm_str[] = " comm=\"";
    static const char comm_str[] = " comm=\"";
    const char* comm = strstr(str, comm_str);
    const char* comm = strstr(str, comm_str);
    const char* estr = str + strlen(str);
    const char* estr = str + strlen(str);
    const char* commfree = NULL;
    const char* commfree = nullptr;
    if (comm) {
    if (comm) {
        estr = comm;
        estr = comm;
        comm += sizeof(comm_str) - 1;
        comm += sizeof(comm_str) - 1;
+8 −8
Original line number Original line Diff line number Diff line
@@ -91,7 +91,7 @@ unsigned short LogBufferElement::setDropped(unsigned short value) {


// caller must own and free character string
// caller must own and free character string
char* android::tidToName(pid_t tid) {
char* android::tidToName(pid_t tid) {
    char* retval = NULL;
    char* retval = nullptr;
    char buffer[256];
    char buffer[256];
    snprintf(buffer, sizeof(buffer), "/proc/%u/comm", tid);
    snprintf(buffer, sizeof(buffer), "/proc/%u/comm", tid);
    int fd = open(buffer, O_RDONLY);
    int fd = open(buffer, O_RDONLY);
@@ -114,7 +114,7 @@ char* android::tidToName(pid_t tid) {
    char* name = android::pidToName(tid);
    char* name = android::pidToName(tid);
    if (!retval) {
    if (!retval) {
        retval = name;
        retval = name;
        name = NULL;
        name = nullptr;
    }
    }


    // check if comm is truncated, see if cmdline has full representation
    // 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 (!strncmp(name + 1, commName + 1, len)) {
            if (commName[len + 1] == '\0') {
            if (commName[len + 1] == '\0') {
                free(const_cast<char*>(commName));
                free(const_cast<char*>(commName));
                commName = NULL;
                commName = nullptr;
            } else {
            } else {
                free(const_cast<char*>(name));
                free(const_cast<char*>(name));
                name = NULL;
                name = nullptr;
            }
            }
        }
        }
    }
    }
    if (name) {
    if (name) {
        char* buf = NULL;
        char* buf = nullptr;
        asprintf(&buf, "(%s)", name);
        asprintf(&buf, "(%s)", name);
        if (buf) {
        if (buf) {
            free(const_cast<char*>(name));
            free(const_cast<char*>(name));
@@ -178,7 +178,7 @@ size_t LogBufferElement::populateDroppedMessage(char*& buffer, LogBuffer* parent
        }
        }
    }
    }
    if (commName) {
    if (commName) {
        char* buf = NULL;
        char* buf = nullptr;
        asprintf(&buf, " %s", commName);
        asprintf(&buf, " %s", commName);
        if (buf) {
        if (buf) {
            free(const_cast<char*>(commName));
            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
    // identical to below to calculate the buffer size required
    const char* type = lastSame ? "identical" : "expire";
    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(),
                          commName ? commName : "", type, getDropped(),
                          (getDropped() > 1) ? "s" : "");
                          (getDropped() > 1) ? "s" : "");


@@ -247,7 +247,7 @@ log_time LogBufferElement::flushTo(SocketClient* reader, LogBuffer* parent,
    iovec[0].iov_base = &entry;
    iovec[0].iov_base = &entry;
    iovec[0].iov_len = entry.hdr_size;
    iovec[0].iov_len = entry.hdr_size;


    char* buffer = NULL;
    char* buffer = nullptr;


    if (mDropped) {
    if (mDropped) {
        entry.len = populateDroppedMessage(buffer, parent, lastSame);
        entry.len = populateDroppedMessage(buffer, parent, lastSame);
Loading