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

Commit c67f9a4c authored by Yi Kong's avatar Yi Kong
Browse files

[cmds] Modernize codebase by replacing NULL with nullptr

Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I73a0a82e3e32001f8ffb0880250c7023dd8290d3
parent 2d38d8e7
Loading
Loading
Loading
Loading
+26 −26
Original line number Diff line number Diff line
@@ -229,8 +229,8 @@ static int g_traceBufferSizeKB = 2048;
static bool g_compress = false;
static bool g_nohup = false;
static int g_initialSleepSecs = 0;
static const char* g_categoriesFile = NULL;
static const char* g_kernelTraceFuncs = NULL;
static const char* g_categoriesFile = nullptr;
static const char* g_kernelTraceFuncs = nullptr;
static const char* g_debugAppCmdLine = "";
static const char* g_outputFile = nullptr;

@@ -406,7 +406,7 @@ static bool isCategorySupported(const TracingCategory& category)
    for (int i = 0; i < MAX_SYS_FILES; i++) {
        const char* path = category.sysfiles[i].path;
        bool req = category.sysfiles[i].required == REQ;
        if (path != NULL) {
        if (path != nullptr) {
            if (req) {
                if (!fileIsWritable(path)) {
                    return false;
@@ -431,7 +431,7 @@ static bool isCategorySupportedForRoot(const TracingCategory& category)
    for (int i = 0; i < MAX_SYS_FILES; i++) {
        const char* path = category.sysfiles[i].path;
        bool req = category.sysfiles[i].required == REQ;
        if (path != NULL) {
        if (path != nullptr) {
            if (req) {
                if (!fileExists(path)) {
                    return false;
@@ -547,10 +547,10 @@ static bool pokeBinderServices()
    Vector<String16> services = sm->listServices();
    for (size_t i = 0; i < services.size(); i++) {
        sp<IBinder> obj = sm->checkService(services[i]);
        if (obj != NULL) {
        if (obj != nullptr) {
            Parcel data;
            if (obj->transact(IBinder::SYSPROPS_TRANSACTION, data,
                    NULL, 0) != OK) {
                    nullptr, 0) != OK) {
                if (false) {
                    // XXX: For some reason this fails on tablets trying to
                    // poke the "phone" service.  It's not clear whether some
@@ -640,9 +640,9 @@ static bool setAppCmdlineProperty(char* cmdline)
{
    int i = 0;
    char* start = cmdline;
    while (start != NULL) {
    while (start != nullptr) {
        char* end = strchr(start, ',');
        if (end != NULL) {
        if (end != nullptr) {
            *end = '\0';
            end++;
        }
@@ -672,7 +672,7 @@ static bool disableKernelTraceEvents() {
        const TracingCategory &c = k_categories[i];
        for (int j = 0; j < MAX_SYS_FILES; j++) {
            const char* path = c.sysfiles[j].path;
            if (path != NULL && fileIsWritable(path)) {
            if (path != nullptr && fileIsWritable(path)) {
                ok &= setKernelOptionEnable(path, false);
            }
        }
@@ -708,7 +708,7 @@ static bool verifyKernelTraceFuncs(const char* funcs)
                ok = false;
            }
        }
        func = strtok(NULL, ",");
        func = strtok(nullptr, ",");
    }
    free(myFuncs);
    return ok;
@@ -719,7 +719,7 @@ static bool setKernelTraceFuncs(const char* funcs)
{
    bool ok = true;

    if (funcs == NULL || funcs[0] == '\0') {
    if (funcs == nullptr || funcs[0] == '\0') {
        // Disable kernel function tracing.
        if (fileIsWritable(k_currentTracerPath)) {
            ok &= writeStr(k_currentTracerPath, "nop");
@@ -741,7 +741,7 @@ static bool setKernelTraceFuncs(const char* funcs)
        char* func = strtok(myFuncs, ",");
        while (func) {
            ok &= appendStr(k_ftraceFilterPath, func);
            func = strtok(NULL, ",");
            func = strtok(nullptr, ",");
        }
        free(myFuncs);

@@ -783,7 +783,7 @@ static bool setCategoriesEnableFromFile(const char* categories_file)
    if (!categories_file) {
        return true;
    }
    Tokenizer* tokenizer = NULL;
    Tokenizer* tokenizer = nullptr;
    if (Tokenizer::open(String8(categories_file), &tokenizer) != NO_ERROR) {
        return false;
    }
@@ -885,7 +885,7 @@ static bool setUpKernelTracing()
            for (int j = 0; j < MAX_SYS_FILES; j++) {
                const char* path = c.sysfiles[j].path;
                bool required = c.sysfiles[j].required == REQ;
                if (path != NULL) {
                if (path != nullptr) {
                    if (fileIsWritable(path)) {
                        ok &= setKernelOptionEnable(path, true);
                    } else if (required) {
@@ -910,7 +910,7 @@ static void cleanUpKernelTracing()
    setTraceOverwriteEnable(true);
    setTraceBufferSizeKB(1);
    setPrintTgidEnableIfPresent(false);
    setKernelTraceFuncs(NULL);
    setKernelTraceFuncs(nullptr);
    setUserInitiatedTraceProperty(false);
}

@@ -1068,10 +1068,10 @@ static void registerSigHandler()
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    sa.sa_handler = handleSignal;
    sigaction(SIGHUP, &sa, NULL);
    sigaction(SIGINT, &sa, NULL);
    sigaction(SIGQUIT, &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);
    sigaction(SIGHUP, &sa, nullptr);
    sigaction(SIGINT, &sa, nullptr);
    sigaction(SIGQUIT, &sa, nullptr);
    sigaction(SIGTERM, &sa, nullptr);
}

static void listSupportedCategories()
@@ -1161,13 +1161,13 @@ int main(int argc, char **argv)
        int ret;
        int option_index = 0;
        static struct option long_options[] = {
            {"async_start",       no_argument, 0,  0 },
            {"async_stop",        no_argument, 0,  0 },
            {"async_dump",        no_argument, 0,  0 },
            {"only_userspace",    no_argument, 0,  0 },
            {"list_categories",   no_argument, 0,  0 },
            {"stream",            no_argument, 0,  0 },
            {           0,                  0, 0,  0 }
            {"async_start",       no_argument, nullptr,  0 },
            {"async_stop",        no_argument, nullptr,  0 },
            {"async_dump",        no_argument, nullptr,  0 },
            {"only_userspace",    no_argument, nullptr,  0 },
            {"list_categories",   no_argument, nullptr,  0 },
            {"stream",            no_argument, nullptr,  0 },
            {nullptr,                       0, nullptr,  0 }
        };

        ret = getopt_long(argc, argv, "a:b:cf:k:ns:t:zo:",
+6 −6
Original line number Diff line number Diff line
@@ -103,12 +103,12 @@ public:
        }
        if (is_selinux_enabled() && seLinuxContext.size() > 0) {
            String8 seLinuxContext8(seLinuxContext);
            security_context_t tmp = NULL;
            security_context_t tmp = nullptr;
            getfilecon(fullPath.string(), &tmp);
            Unique_SecurityContext context(tmp);
            if (checkWrite) {
                int accessGranted = selinux_check_access(seLinuxContext8.string(), context.get(),
                        "file", "write", NULL);
                        "file", "write", nullptr);
                if (accessGranted != 0) {
#if DEBUG
                    ALOGD("openFile: failed selinux write check!");
@@ -122,7 +122,7 @@ public:
            }
            if (checkRead) {
                int accessGranted = selinux_check_access(seLinuxContext8.string(), context.get(),
                        "file", "read", NULL);
                        "file", "read", nullptr);
                if (accessGranted != 0) {
#if DEBUG
                    ALOGD("openFile: failed selinux read check!");
@@ -174,7 +174,7 @@ int main(int argc, char* const argv[])
#endif
    sp<IServiceManager> sm = defaultServiceManager();
    fflush(stdout);
    if (sm == NULL) {
    if (sm == nullptr) {
        ALOGW("Unable to get default service manager!");
        aerr << "cmd: Unable to get default service manager!" << endl;
        return 20;
@@ -192,7 +192,7 @@ int main(int argc, char* const argv[])

        for (size_t i=0; i<services.size(); i++) {
            sp<IBinder> service = sm->checkService(services[i]);
            if (service != NULL) {
            if (service != nullptr) {
                aout << "  " << services[i] << endl;
            }
        }
@@ -205,7 +205,7 @@ int main(int argc, char* const argv[])
    }
    String16 cmd = String16(argv[1]);
    sp<IBinder> service = sm->checkService(cmd);
    if (service == NULL) {
    if (service == nullptr) {
        ALOGW("Can't find service %s", argv[1]);
        aerr << "cmd: Can't find service: " << argv[1] << endl;
        return 20;
+3 −3
Original line number Diff line number Diff line
@@ -56,11 +56,11 @@ static bool waitpid_with_timeout(pid_t pid, int timeout_ms, int* status) {
    timespec ts;
    ts.tv_sec = MSEC_TO_SEC(timeout_ms);
    ts.tv_nsec = (timeout_ms % 1000) * 1000000;
    int ret = TEMP_FAILURE_RETRY(sigtimedwait(&child_mask, NULL, &ts));
    int ret = TEMP_FAILURE_RETRY(sigtimedwait(&child_mask, nullptr, &ts));
    int saved_errno = errno;

    // Set the signals back the way they were.
    if (sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1) {
    if (sigprocmask(SIG_SETMASK, &old_mask, nullptr) == -1) {
        printf("*** sigprocmask failed: %s\n", strerror(errno));
        if (ret == 0) {
            return false;
@@ -310,7 +310,7 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri
        struct sigaction sigact;
        memset(&sigact, 0, sizeof(sigact));
        sigact.sa_handler = SIG_IGN;
        sigaction(SIGPIPE, &sigact, NULL);
        sigaction(SIGPIPE, &sigact, nullptr);

        execvp(path, (char**)args.data());
        // execvp's result will be handled after waitpid_with_timeout() below, but
+6 −6
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ using android::os::dumpstate::PropertiesHelper;

/* read before root is shed */
static char cmdline_buf[16384] = "(unknown)";
static const char *dump_traces_path = NULL;
static const char *dump_traces_path = nullptr;

// TODO: variables and functions below should be part of dumpstate object

@@ -295,7 +295,7 @@ static void dump_dev_files(const char *title, const char *driverpath, const char
    char path[PATH_MAX];

    d = opendir(driverpath);
    if (d == NULL) {
    if (d == nullptr) {
        return;
    }

@@ -587,7 +587,7 @@ unsigned long worst_write_perf = 20000; /* in KB/s */
static int dump_stat_from_fd(const char *title __unused, const char *path, int fd) {
    unsigned long long fields[__STAT_NUMBER_FIELD];
    bool z;
    char *cp, *buffer = NULL;
    char *cp, *buffer = nullptr;
    size_t i = 0;
    FILE *fp = fdopen(dup(fd), "rb");
    getline(&buffer, &i, fp);
@@ -1686,7 +1686,7 @@ static std::string SHA256_file_hash(const std::string& filepath) {
            | O_CLOEXEC | O_NOFOLLOW)));
    if (fd == -1) {
        MYLOGE("open(%s): %s\n", filepath.c_str(), strerror(errno));
        return NULL;
        return nullptr;
    }

    SHA256_CTX ctx;
@@ -1699,7 +1699,7 @@ static std::string SHA256_file_hash(const std::string& filepath) {
            break;
        } else if (bytes_read == -1) {
            MYLOGE("read(%s): %s\n", filepath.c_str(), strerror(errno));
            return NULL;
            return nullptr;
        }

        SHA256_Update(&ctx, buffer.data(), bytes_read);
@@ -1748,7 +1748,7 @@ int run_main(int argc, char* argv[]) {
    int do_add_date = 0;
    int do_zip_file = 0;
    int do_vibrate = 1;
    char* use_outfile = 0;
    char* use_outfile = nullptr;
    int use_socket = 0;
    int use_control_socket = 0;
    int do_fb = 0;
+6 −6
Original line number Diff line number Diff line
@@ -525,13 +525,13 @@ void do_dmesg() {
    if (PropertiesHelper::IsDryRun()) return;

    /* Get size of kernel buffer */
    int size = klogctl(KLOG_SIZE_BUFFER, NULL, 0);
    int size = klogctl(KLOG_SIZE_BUFFER, nullptr, 0);
    if (size <= 0) {
        printf("Unexpected klogctl return value: %d\n\n", size);
        return;
    }
    char *buf = (char *) malloc(size + 1);
    if (buf == NULL) {
    if (buf == nullptr) {
        printf("memory allocation failed\n\n");
        return;
    }
@@ -598,7 +598,7 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha
    DurationReporter duration_reporter(title);
    DIR *dirp;
    struct dirent *d;
    char *newpath = NULL;
    char *newpath = nullptr;
    const char *slash = "/";
    int retval = 0;

@@ -611,7 +611,7 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha
        ++slash;
    }
    dirp = opendir(dir);
    if (dirp == NULL) {
    if (dirp == nullptr) {
        retval = -errno;
        MYLOGE("%s: %s\n", dir, strerror(errno));
        return retval;
@@ -620,7 +620,7 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha
    if (!dump_from_fd) {
        dump_from_fd = dump_file_from_fd;
    }
    for (; ((d = readdir(dirp))); free(newpath), newpath = NULL) {
    for (; ((d = readdir(dirp))); free(newpath), newpath = nullptr) {
        if ((d->d_name[0] == '.')
         && (((d->d_name[1] == '.') && (d->d_name[2] == '\0'))
          || (d->d_name[1] == '\0'))) {
@@ -648,7 +648,7 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha
            printf("*** %s: %s\n", newpath, strerror(errno));
            continue;
        }
        (*dump_from_fd)(NULL, newpath, fd.get());
        (*dump_from_fd)(nullptr, newpath, fd.get());
    }
    closedir(dirp);
    if (!title.empty()) {
Loading