update_engine: Replace NULL with nullptr

Replaced the usage of NULL with nullptr. This also makes it possible to
use standard gtest macros to compare pointers in Update Manager's unit tests.
So, there is no need in custom UMTEST_... macros which are replaced with the
gtest macros (see change in update_engine/update_manager/umtest_utils.h):

UMTEST_ASSERT_NULL(p)      => ASSERT_EQ(nullptr, p)
UMTEST_ASSERT_NOT_NULL(p)  => ASSERT_NE(nullptr, p)
UMTEST_EXPECT_NULL(p)      => EXPECT_EQ(nullptr, p)
UMTEST_EXPECT_NOT_NULL(p)  => EXPECT_NE(nullptr, p)

BUG=None
TEST=FEATURES=test emerge-link update_engine
     USE="clang asan" FEATURES=test emerge-link update_engine

Change-Id: I77a42a1e9ce992bb2f9f263db5cf75fe6110a4ec
Reviewed-on: https://chromium-review.googlesource.com/215136
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/payload_generator/delta_diff_generator.cc b/payload_generator/delta_diff_generator.cc
index 1a15f3a..8236292 100644
--- a/payload_generator/delta_diff_generator.cc
+++ b/payload_generator/delta_diff_generator.cc
@@ -105,7 +105,7 @@
 // For a given regular file which must exist at new_root + path, and
 // may exist at old_root + path, creates a new InstallOperation and
 // adds it to the graph. Also, populates the |blocks| array as
-// necessary, if |blocks| is non-NULL.  Also, writes the data
+// necessary, if |blocks| is non-null.  Also, writes the data
 // necessary to send the file down to the client into data_fd, which
 // has length *data_file_size. *data_file_size is updated
 // appropriately. If |existing_vertex| is no kInvalidIndex, use that
@@ -296,7 +296,7 @@
   string temp_file_path;
   TEST_AND_RETURN_FALSE(utils::MakeTempFile("CrAU_temp_data.XXXXXX",
                                             &temp_file_path,
-                                            NULL));
+                                            nullptr));
 
   FILE* file = fopen(temp_file_path.c_str(), "w");
   TEST_AND_RETURN_FALSE(file);
@@ -364,11 +364,11 @@
       }
     }
   }
-  BZ2_bzWriteClose(&err, bz_file, 0, NULL, NULL);
+  BZ2_bzWriteClose(&err, bz_file, 0, nullptr, nullptr);
   TEST_AND_RETURN_FALSE(err == BZ_OK);
-  bz_file = NULL;
+  bz_file = nullptr;
   TEST_AND_RETURN_FALSE_ERRNO(0 == fclose(file));
-  file = NULL;
+  file = nullptr;
 
   vector<char> compressed_data;
   LOG(INFO) << "Reading compressed data off disk";
@@ -1385,7 +1385,7 @@
 
   for (int i = 0; i < (manifest->install_operations_size() +
                        manifest->kernel_install_operations_size()); i++) {
-    DeltaArchiveManifest_InstallOperation* op = NULL;
+    DeltaArchiveManifest_InstallOperation* op = nullptr;
     if (i < manifest->install_operations_size()) {
       op = manifest->mutable_install_operations(i);
     } else {
@@ -1439,7 +1439,7 @@
 
     TEST_AND_RETURN_FALSE(DeltaReadFile(graph,
                                         cut.old_dst,
-                                        NULL,
+                                        nullptr,
                                         kEmptyPath,
                                         new_root,
                                         (*graph)[cut.old_dst].file_name,
@@ -1719,7 +1719,7 @@
   TEST_AND_RETURN_FALSE(utils::MakeTempFile(
       "CrAU_temp_data.ordered.XXXXXX",
       &ordered_blobs_path,
-      NULL));
+      nullptr));
   ScopedPathUnlinker ordered_blobs_unlinker(ordered_blobs_path);
   TEST_AND_RETURN_FALSE(ReorderDataBlobs(&manifest,
                                          temp_file_path,
@@ -1838,7 +1838,7 @@
   string patch_file_path;
 
   TEST_AND_RETURN_FALSE(
-      utils::MakeTempFile(kPatchFile, &patch_file_path, NULL));
+      utils::MakeTempFile(kPatchFile, &patch_file_path, nullptr));
 
   vector<string> cmd;
   cmd.push_back(kBsdiffPath);
@@ -1848,7 +1848,7 @@
 
   int rc = 1;
   vector<char> patch_file;
-  TEST_AND_RETURN_FALSE(Subprocess::SynchronousExec(cmd, &rc, NULL));
+  TEST_AND_RETURN_FALSE(Subprocess::SynchronousExec(cmd, &rc, nullptr));
   TEST_AND_RETURN_FALSE(rc == 0);
   TEST_AND_RETURN_FALSE(utils::ReadFile(patch_file_path, out));
   unlink(patch_file_path.c_str());
diff --git a/payload_generator/delta_diff_generator_unittest.cc b/payload_generator/delta_diff_generator_unittest.cc
index 977b34d..85d041c 100644
--- a/payload_generator/delta_diff_generator_unittest.cc
+++ b/payload_generator/delta_diff_generator_unittest.cc
@@ -64,9 +64,9 @@
 
   virtual void SetUp() {
     ASSERT_TRUE(utils::MakeTempFile("DeltaDiffGeneratorTest-old_path-XXXXXX",
-                                    &old_path_, NULL));
+                                    &old_path_, nullptr));
     ASSERT_TRUE(utils::MakeTempFile("DeltaDiffGeneratorTest-new_path-XXXXXX",
-                                    &new_path_, NULL));
+                                    &new_path_, nullptr));
   }
 
   virtual void TearDown() {
@@ -556,8 +556,8 @@
 
 TEST_F(DeltaDiffGeneratorTest, ReorderBlobsTest) {
   string orig_blobs;
-  EXPECT_TRUE(
-      utils::MakeTempFile("ReorderBlobsTest.orig.XXXXXX", &orig_blobs, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("ReorderBlobsTest.orig.XXXXXX", &orig_blobs,
+                                  nullptr));
 
   string orig_data = "abcd";
   EXPECT_TRUE(
@@ -565,7 +565,7 @@
 
   string new_blobs;
   EXPECT_TRUE(
-      utils::MakeTempFile("ReorderBlobsTest.new.XXXXXX", &new_blobs, NULL));
+      utils::MakeTempFile("ReorderBlobsTest.new.XXXXXX", &new_blobs, nullptr));
 
   DeltaArchiveManifest manifest;
   DeltaArchiveManifest_InstallOperation* op =
@@ -718,7 +718,7 @@
 
   int fd;
   EXPECT_TRUE(utils::MakeTempFile("AssignTempBlocksTestData.XXXXXX",
-                                  NULL,
+                                  nullptr,
                                   &fd));
   ScopedFdCloser fd_closer(&fd);
   off_t data_file_size = 0;
@@ -835,7 +835,7 @@
 
   int fd = -1;
   EXPECT_TRUE(utils::MakeTempFile("NoSparseAsTempTestData.XXXXXX",
-                                  NULL,
+                                  nullptr,
                                   &fd));
   ScopedFdCloser fd_closer(&fd);
   off_t data_file_size = 0;
@@ -1096,7 +1096,7 @@
 
   int fd;
   EXPECT_TRUE(utils::MakeTempFile("AssignTempBlocksReuseTest.XXXXXX",
-                                  NULL,
+                                  nullptr,
                                   &fd));
   ScopedFdCloser fd_closer(&fd);
   off_t data_file_size = 0;
diff --git a/payload_generator/filesystem_iterator_unittest.cc b/payload_generator/filesystem_iterator_unittest.cc
index 7436c99..047c8a4 100644
--- a/payload_generator/filesystem_iterator_unittest.cc
+++ b/payload_generator/filesystem_iterator_unittest.cc
@@ -52,12 +52,12 @@
   // Create uniquely named main/sub images.
   string main_image;
   ASSERT_TRUE(utils::MakeTempFile("FilesystemIteratorTest.image1-XXXXXX",
-                                  &main_image, NULL));
+                                  &main_image, nullptr));
   ScopedPathUnlinker main_image_unlinker(main_image);
 
   string sub_image;
   ASSERT_TRUE(utils::MakeTempFile("FilesystemIteratorTest.image2-XXXXXX",
-                                  &sub_image, NULL));
+                                  &sub_image, nullptr));
   ScopedPathUnlinker sub_image_unlinker(sub_image);
 
   // Create uniquely named main/sub mount points.
@@ -70,7 +70,7 @@
 
   vector<string> expected_paths_vector;
   CreateExtImageAtPath(main_image, &expected_paths_vector);
-  CreateExtImageAtPath(sub_image, NULL);
+  CreateExtImageAtPath(sub_image, nullptr);
   ASSERT_EQ(0, System(string("mount -o loop ") + main_image + " " +
                       main_image_mount_point));
   ASSERT_EQ(0, System(string("mount -o loop ") + sub_image + " " +
diff --git a/payload_generator/full_update_generator.cc b/payload_generator/full_update_generator.cc
index d4d6614..5b6a6b3 100644
--- a/payload_generator/full_update_generator.cc
+++ b/payload_generator/full_update_generator.cc
@@ -35,7 +35,7 @@
  public:
   // Read a chunk of |size| bytes from |fd| starting at offset |offset|.
   ChunkProcessor(int fd, off_t offset, size_t size)
-      : thread_(NULL),
+      : thread_(nullptr),
         fd_(fd),
         offset_(offset),
         buffer_in_(size) {}
@@ -74,8 +74,9 @@
 bool ChunkProcessor::Start() {
   // g_thread_create is deprecated since glib 2.32. Use
   // g_thread_new instead.
-  thread_ = g_thread_try_new("chunk_proc", ReadAndCompressThread, this, NULL);
-  TEST_AND_RETURN_FALSE(thread_ != NULL);
+  thread_ = g_thread_try_new("chunk_proc", ReadAndCompressThread, this,
+                             nullptr);
+  TEST_AND_RETURN_FALSE(thread_ != nullptr);
   return true;
 }
 
@@ -84,14 +85,14 @@
     return false;
   }
   gpointer result = g_thread_join(thread_);
-  thread_ = NULL;
+  thread_ = nullptr;
   TEST_AND_RETURN_FALSE(result == this);
   return true;
 }
 
 gpointer ChunkProcessor::ReadAndCompressThread(gpointer data) {
-  return
-      reinterpret_cast<ChunkProcessor*>(data)->ReadAndCompress() ? data : NULL;
+  return reinterpret_cast<ChunkProcessor*>(data)->ReadAndCompress() ?
+      data : nullptr;
 }
 
 bool ChunkProcessor::ReadAndCompress() {
@@ -161,7 +162,7 @@
       threads.pop_front();
       TEST_AND_RETURN_FALSE(processor->Wait());
 
-      DeltaArchiveManifest_InstallOperation* op = NULL;
+      DeltaArchiveManifest_InstallOperation* op = nullptr;
       if (partition == 0) {
         graph->resize(graph->size() + 1);
         graph->back().file_name =
diff --git a/payload_generator/full_update_generator_unittest.cc b/payload_generator/full_update_generator_unittest.cc
index 689c5ce..7cb2d7a 100644
--- a/payload_generator/full_update_generator_unittest.cc
+++ b/payload_generator/full_update_generator_unittest.cc
@@ -35,14 +35,14 @@
   string new_root_path;
   EXPECT_TRUE(utils::MakeTempFile("NewFullUpdateTest_R.XXXXXX",
                                   &new_root_path,
-                                  NULL));
+                                  nullptr));
   ScopedPathUnlinker new_root_path_unlinker(new_root_path);
   EXPECT_TRUE(WriteFileVector(new_root_path, new_root));
 
   string new_kern_path;
   EXPECT_TRUE(utils::MakeTempFile("NewFullUpdateTest_K.XXXXXX",
                                   &new_kern_path,
-                                  NULL));
+                                  nullptr));
   ScopedPathUnlinker new_kern_path_unlinker(new_kern_path);
   EXPECT_TRUE(WriteFileVector(new_kern_path, new_kern));
 
diff --git a/payload_generator/generate_delta_main.cc b/payload_generator/generate_delta_main.cc
index a2b6b3c..38c4e76 100644
--- a/payload_generator/generate_delta_main.cc
+++ b/payload_generator/generate_delta_main.cc
@@ -264,7 +264,7 @@
                                   kern_info.hash().end());
   install_plan.rootfs_hash.assign(root_info.hash().begin(),
                                   root_info.hash().end());
-  DeltaPerformer performer(&prefs, NULL, &install_plan);
+  DeltaPerformer performer(&prefs, nullptr, &install_plan);
   CHECK_EQ(performer.Open(FLAGS_old_image.c_str(), 0, 0), 0);
   CHECK(performer.OpenKernel(FLAGS_old_kernel.c_str()));
   vector<char> buf(1024 * 1024);
@@ -378,7 +378,7 @@
       FLAGS_private_key,
       FLAGS_chunk_size,
       FLAGS_rootfs_partition_size,
-      is_delta ? &old_image_info : NULL,
+      is_delta ? &old_image_info : nullptr,
       &new_image_info,
       &metadata_size)) {
     return 1;
diff --git a/payload_generator/metadata.cc b/payload_generator/metadata.cc
index 7ed1727..460aa46 100644
--- a/payload_generator/metadata.cc
+++ b/payload_generator/metadata.cc
@@ -359,7 +359,7 @@
     bool all_blocks = ((ino == EXT2_JOURNAL_INO) || is_old_dir || is_new_dir);
 
     vector<Extent> old_extents;
-    error = ext2fs_block_iterate2(fs_old, ino, 0, NULL,
+    error = ext2fs_block_iterate2(fs_old, ino, 0, nullptr,
                                   all_blocks ? ProcessInodeAllBlocks :
                                                ProcessInodeMetadataBlocks,
                                   &old_extents);
@@ -370,7 +370,7 @@
     }
 
     vector<Extent> new_extents;
-    error = ext2fs_block_iterate2(fs_new, ino, 0, NULL,
+    error = ext2fs_block_iterate2(fs_new, ino, 0, nullptr,
                                   all_blocks ? ProcessInodeAllBlocks :
                                                ProcessInodeMetadataBlocks,
                                   &new_extents);
diff --git a/payload_generator/metadata_unittest.cc b/payload_generator/metadata_unittest.cc
index dcce0c3..93b0917 100644
--- a/payload_generator/metadata_unittest.cc
+++ b/payload_generator/metadata_unittest.cc
@@ -32,9 +32,9 @@
 
 TEST_F(MetadataTest, RunAsRootReadMetadataDissimilarFileSystems) {
   string a_img, b_img;
-  EXPECT_TRUE(utils::MakeTempFile("a_img.XXXXXX", &a_img, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("a_img.XXXXXX", &a_img, nullptr));
   ScopedPathUnlinker a_img_unlinker(a_img);
-  EXPECT_TRUE(utils::MakeTempFile("b_img.XXXXXX", &b_img, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("b_img.XXXXXX", &b_img, nullptr));
   ScopedPathUnlinker b_img_unlinker(b_img);
 
   CreateEmptyExtImageAtPath(a_img, 10485759, 4096);
@@ -47,7 +47,7 @@
                                           a_img,
                                           b_img,
                                           0,
-                                          NULL));
+                                          nullptr));
   EXPECT_EQ(graph.size(), 0);
 
   CreateEmptyExtImageAtPath(a_img, 10485759, 4096);
@@ -60,17 +60,17 @@
                                           a_img,
                                           b_img,
                                           0,
-                                          NULL));
+                                          nullptr));
   EXPECT_EQ(graph.size(), 0);
 }
 
 TEST_F(MetadataTest, RunAsRootReadMetadata) {
   string a_img, b_img, data_file;
-  EXPECT_TRUE(utils::MakeTempFile("a_img.XXXXXX", &a_img, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("a_img.XXXXXX", &a_img, nullptr));
   ScopedPathUnlinker a_img_unlinker(a_img);
-  EXPECT_TRUE(utils::MakeTempFile("b_img.XXXXXX", &b_img, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("b_img.XXXXXX", &b_img, nullptr));
   ScopedPathUnlinker b_img_unlinker(b_img);
-  EXPECT_TRUE(utils::MakeTempFile("data_file.XXXXXX", &data_file, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("data_file.XXXXXX", &data_file, nullptr));
   ScopedPathUnlinker data_file_unlinker(data_file);
 
   const size_t image_size = (256 * 1024 * 1024);  // Enough for 2 block groups
diff --git a/payload_generator/payload_signer.cc b/payload_generator/payload_signer.cc
index 4bbb155..9a9008f 100644
--- a/payload_generator/payload_signer.cc
+++ b/payload_generator/payload_signer.cc
@@ -128,12 +128,12 @@
   LOG(INFO) << "Signing hash with private key: " << private_key_path;
   string sig_path;
   TEST_AND_RETURN_FALSE(
-      utils::MakeTempFile("signature.XXXXXX", &sig_path, NULL));
+      utils::MakeTempFile("signature.XXXXXX", &sig_path, nullptr));
   ScopedPathUnlinker sig_path_unlinker(sig_path);
 
   string hash_path;
   TEST_AND_RETURN_FALSE(
-      utils::MakeTempFile("hash.XXXXXX", &hash_path, NULL));
+      utils::MakeTempFile("hash.XXXXXX", &hash_path, nullptr));
   ScopedPathUnlinker hash_path_unlinker(hash_path);
   // We expect unpadded SHA256 hash coming in
   TEST_AND_RETURN_FALSE(hash.size() == 32);
@@ -158,7 +158,8 @@
   cmd[0] = utils::GetPathOnBoard("openssl");
 
   int return_code = 0;
-  TEST_AND_RETURN_FALSE(Subprocess::SynchronousExec(cmd, &return_code, NULL));
+  TEST_AND_RETURN_FALSE(Subprocess::SynchronousExec(cmd, &return_code,
+                                                    nullptr));
   TEST_AND_RETURN_FALSE(return_code == 0);
 
   vector<char> signature;
@@ -193,7 +194,7 @@
 
   string x_path;
   TEST_AND_RETURN_FALSE(
-      utils::MakeTempFile("signed_data.XXXXXX", &x_path, NULL));
+      utils::MakeTempFile("signed_data.XXXXXX", &x_path, nullptr));
   ScopedPathUnlinker x_path_unlinker(x_path);
   TEST_AND_RETURN_FALSE(utils::WriteFile(x_path.c_str(), "x", 1));
 
diff --git a/payload_generator/payload_signer_unittest.cc b/payload_generator/payload_signer_unittest.cc
index 00df88c..c2cd209 100644
--- a/payload_generator/payload_signer_unittest.cc
+++ b/payload_generator/payload_signer_unittest.cc
@@ -85,7 +85,7 @@
 void SignSampleData(vector<char>* out_signature_blob) {
   string data_path;
   ASSERT_TRUE(
-      utils::MakeTempFile("data.XXXXXX", &data_path, NULL));
+      utils::MakeTempFile("data.XXXXXX", &data_path, nullptr));
   ScopedPathUnlinker data_path_unlinker(data_path);
   ASSERT_TRUE(utils::WriteFile(data_path.c_str(),
                                kDataToSign,