Change 0 or NULL to nullptr 01/229601/1
authorSeungha Son <seungha.son@samsung.com>
Thu, 2 Apr 2020 06:17:28 +0000 (15:17 +0900)
committerSeungha Son <seungha.son@samsung.com>
Thu, 2 Apr 2020 06:19:17 +0000 (15:19 +0900)
 nullptr is a keyword that can be used at all places
 where NULL is expected. Like NULL, nullptr is implicitly
 convertible and comparable to any pointer type.
 Unlike NULL, it is not implicitly convertible or
 comparable to integral types.

Change-Id: Ie1ea211adaff6f818d1f86b0e0a8d9736320b0bf
Signed-off-by: Seungha Son <seungha.son@samsung.com>
src/atrace/atrace.cpp

index 702eecf445f1e687f6bcb1c016f26582b45eb309..8fcc67e2670f404ad2c97c05dabd47e89962509d 100755 (executable)
@@ -62,7 +62,7 @@ struct TracingCategory {
     // The userland tracing tags that the category enables.
     uint64_t tags;
 
-    // The fname==NULL terminated list of /sys/ files that the category
+    // The fname==nullptr terminated list of /sys/ files that the category
     // enables.
     struct {
         // Whether the file must be writable in order to enable the tracing
@@ -183,7 +183,7 @@ static int g_traceBufferSizeKB = 2048;
 static bool g_compress = false;
 static bool g_nohup = false;
 static int g_initialSleepSecs = 0;
-static const char* g_kernelTraceFuncs = NULL;
+static const char* g_kernelTraceFuncs = nullptr;
 static const char* g_debugAppCmdLine = "";
 
 /* Global state */
@@ -316,7 +316,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;
@@ -341,7 +341,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;
@@ -404,10 +404,10 @@ static bool setPrintTgidEnableIfPresent(bool enable)
 static bool getBootupTagStr(char* bootupTagStr, int strSize)
 {
     if(fileExists(BOOTUP_TRACE)) {
-        FILE *bootupTagFile = NULL;
+        FILE *bootupTagFile = nullptr;
 
         bootupTagFile = fopen(BOOTUP_TRACE, "r");
-        if (bootupTagFile == NULL) {
+        if (bootupTagFile == nullptr) {
             return false;
         }
         if (fgets(bootupTagStr, strSize, bootupTagFile) == NULL) {
@@ -427,17 +427,17 @@ static void setBootupTags(char* bootupTagStr)
     char* tagPtr;
     char* nextTagPtr;
     tagPtr = strtok_r(bootupTagStr, " \n", &nextTagPtr);
-    while (tagPtr != NULL) {
+    while (tagPtr != nullptr) {
         setCategoryEnable(tagPtr, true);
         fprintf(stderr, "[Info] Tag %s enabled\n", tagPtr);
-        tagPtr = strtok_r(NULL, " \n", &nextTagPtr);
+        tagPtr = strtok_r(nullptr, " \n", &nextTagPtr);
     }
     return;
 }
 
 static bool initEnabledTagFile()
 {
-    uint64_t *sm_for_enabled_tag = NULL;
+    uint64_t *sm_for_enabled_tag = nullptr;
     int fd = -1;
 
     if(fileExists(ENABLED_TAG_FILE)) {
@@ -456,7 +456,7 @@ static bool initEnabledTagFile()
         close(fd);
         return false;
     }
-    sm_for_enabled_tag = (uint64_t*)mmap(NULL, sizeof(uint64_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+    sm_for_enabled_tag = (uint64_t*)mmap(nullptr, sizeof(uint64_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 
     if(sm_for_enabled_tag == MAP_FAILED) {
         fprintf(stderr, "mmap() failed(%s)\n", strerror_r(errno, str_error, sizeof(str_error)));
@@ -478,7 +478,7 @@ static bool initEnabledTagFile()
 // processes to pick up the new value.
 static bool setTagsProperty(uint64_t tags)
 {
-    uint64_t *sm_for_enabled_tag = NULL;
+    uint64_t *sm_for_enabled_tag = nullptr;
     int fd = -1;
 
     // atrace normal mode
@@ -487,7 +487,7 @@ static bool setTagsProperty(uint64_t tags)
         fprintf(stderr, "Fail to open enabled_tag file: %s(%d)\n", strerror_r(errno, str_error, sizeof(str_error)), errno);
         return false;
     }
-    sm_for_enabled_tag = (uint64_t*)mmap(NULL, sizeof(uint64_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+    sm_for_enabled_tag = (uint64_t*)mmap(nullptr, sizeof(uint64_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
     if(sm_for_enabled_tag == MAP_FAILED) {
         fprintf(stderr, "mmap() failed(%s)\n", strerror_r(errno, str_error, sizeof(str_error)));
         close(fd);
@@ -510,7 +510,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);
             }
         }
@@ -524,7 +524,7 @@ static bool setKernelTraceFuncs(const char* funcs)
     bool ok = true;
     char *ptr[2];
 
-    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");
@@ -619,7 +619,7 @@ static bool setUpTrace()
             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) {
@@ -645,7 +645,7 @@ static void cleanUpTrace()
     setTraceBufferSizeKB(1);
     setGlobalClockEnable(false);
     setPrintTgidEnableIfPresent(false);
-    setKernelTraceFuncs(NULL);
+    setKernelTraceFuncs(nullptr);
 }
 
 // Disable tracing in the kernel.
@@ -699,11 +699,11 @@ static void dumpTrace(bool startup)
         const size_t bufSize = 64*1024;
         in = (uint8_t*)malloc(bufSize);
         out = (uint8_t*)malloc(bufSize);
-        if ((in == NULL) || (out == NULL)) {
+        if ((in == nullptr) || (out == nullptr)) {
             fprintf(stderr, "Could not allocate memory");
-            if (in != NULL)
+            if (in != nullptr)
                 free(in);
-            if (out != NULL)
+            if (out != nullptr)
                 free(out);
             close(traceFD);
             if (backup_fd > -1)
@@ -780,9 +780,9 @@ static void dumpTrace(bool startup)
     } else {
         ssize_t sent = 0;
         if (startup)
-            while ((sent = sendfile(backup_fd, traceFD, NULL, 64*1024*1024)) > 0);
+            while ((sent = sendfile(backup_fd, traceFD, nullptr, 64*1024*1024)) > 0);
         else
-            while ((sent = sendfile(STDOUT_FILENO, traceFD, NULL, 64*1024*1024)) > 0);
+            while ((sent = sendfile(STDOUT_FILENO, traceFD, nullptr, 64*1024*1024)) > 0);
 
         if (sent == -1) {
             fprintf(stderr, "error dumping trace: %s (%d)\n", strerror_r(errno, str_error, sizeof(str_error)),
@@ -808,10 +808,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 bool setCategoryEnable(const char* name, bool enable)
@@ -896,14 +896,14 @@ 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 },
-            {"list_categories", no_argument, 0,  0 },
-            {"init_exec",       no_argument, 0,  0 },
-            {"append",          no_argument, 0,  0 },
-            {"backup",          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 },
+            {"list_categories", no_argument, nullptr,  0 },
+            {"init_exec",       no_argument, nullptr,  0 },
+            {"append",          no_argument, nullptr,  0 },
+            {"backup",          no_argument, nullptr,  0 },
+            {0,                 0,           nullptr,  0 }
         };
         ret = getopt_long(argc, argv, "b:ck:e:ns:t:z",
                 long_options, &option_index);