[cmds] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.
Test: m
Bug: 68236239
Change-Id: I1635395d653ace5a11c75795f4a7d2bf2d9e0b1b
Merged-In: I73a0a82e3e32001f8ffb0880250c7023dd8290d3
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 3af8121..5061745 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -63,7 +63,7 @@
/* 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
@@ -267,7 +267,7 @@
char path[PATH_MAX];
d = opendir(driverpath);
- if (d == NULL) {
+ if (d == nullptr) {
return;
}
@@ -559,7 +559,7 @@
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);
@@ -1362,7 +1362,7 @@
| O_CLOEXEC | O_NOFOLLOW)));
if (fd == -1) {
MYLOGE("open(%s): %s\n", filepath.c_str(), strerror(errno));
- return NULL;
+ return nullptr;
}
SHA256_CTX ctx;
@@ -1375,7 +1375,7 @@
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);
@@ -1423,7 +1423,7 @@
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;
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index 6b808e3..1eccea5 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -555,13 +555,13 @@
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;
}
@@ -628,7 +628,7 @@
DurationReporter duration_reporter(title);
DIR *dirp;
struct dirent *d;
- char *newpath = NULL;
+ char *newpath = nullptr;
const char *slash = "/";
int retval = 0;
@@ -641,7 +641,7 @@
++slash;
}
dirp = opendir(dir);
- if (dirp == NULL) {
+ if (dirp == nullptr) {
retval = -errno;
MYLOGE("%s: %s\n", dir, strerror(errno));
return retval;
@@ -650,7 +650,7 @@
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'))) {
@@ -678,7 +678,7 @@
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()) {