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/p2p_manager.cc b/p2p_manager.cc
index 6d1a773..fcaae1a 100644
--- a/p2p_manager.cc
+++ b/p2p_manager.cc
@@ -135,7 +135,7 @@
// Utility function used by EnsureP2PRunning() and EnsureP2PNotRunning().
bool EnsureP2P(bool should_be_running);
- // The device policy being used or NULL if no policy is being used.
+ // The device policy being used or null if no policy is being used.
const policy::DevicePolicy* device_policy_;
// Configuration object.
@@ -170,11 +170,11 @@
PrefsInterface *prefs,
const string& file_extension,
const int num_files_to_keep)
- : device_policy_(NULL),
+ : device_policy_(nullptr),
prefs_(prefs),
file_extension_(file_extension),
num_files_to_keep_(num_files_to_keep) {
- configuration_.reset(configuration != NULL ? configuration :
+ configuration_.reset(configuration != nullptr ? configuration :
new ConfigurationImpl());
}
@@ -195,7 +195,7 @@
// crosh_flag == TRUE && enterprise_policy == FALSE -> use_p2p == TRUE
// crosh_flag == TRUE && enterprise_policy == TRUE -> use_p2p == TRUE
- if (device_policy_ != NULL) {
+ if (device_policy_ != nullptr) {
if (device_policy_->GetAuP2PEnabled(&p2p_enabled)) {
if (p2p_enabled) {
LOG(INFO) << "Enterprise Policy indicates that p2p is enabled.";
@@ -204,7 +204,7 @@
}
}
- if (prefs_ != NULL &&
+ if (prefs_ != nullptr &&
prefs_->Exists(kPrefsP2PEnabled) &&
prefs_->GetBoolean(kPrefsP2PEnabled, &p2p_enabled) &&
p2p_enabled) {
@@ -218,19 +218,19 @@
}
bool P2PManagerImpl::EnsureP2P(bool should_be_running) {
- gchar *standard_error = NULL;
- GError *error = NULL;
+ gchar *standard_error = nullptr;
+ GError *error = nullptr;
gint exit_status = 0;
vector<string> args = configuration_->GetInitctlArgs(should_be_running);
scoped_ptr<gchar*, GLibStrvFreeDeleter> argv(
utils::StringVectorToGStrv(args));
- if (!g_spawn_sync(NULL, // working_directory
+ if (!g_spawn_sync(nullptr, // working_directory
argv.get(),
- NULL, // envp
+ nullptr, // envp
static_cast<GSpawnFlags>(G_SPAWN_SEARCH_PATH),
- NULL, NULL, // child_setup, user_data
- NULL, // standard_output
+ nullptr, nullptr, // child_setup, user_data
+ nullptr, // standard_output
&standard_error,
&exit_status,
&error)) {
@@ -307,16 +307,16 @@
}
bool P2PManagerImpl::PerformHousekeeping() {
- GDir* dir = NULL;
- GError* error = NULL;
- const char* name = NULL;
+ GDir* dir = nullptr;
+ GError* error = nullptr;
+ const char* name = nullptr;
vector<pair<FilePath, Time> > matches;
// Go through all files in the p2p dir and pick the ones that match
// and get their ctime.
base::FilePath p2p_dir = configuration_->GetP2PDir();
dir = g_dir_open(p2p_dir.value().c_str(), 0, &error);
- if (dir == NULL) {
+ if (dir == nullptr) {
LOG(ERROR) << "Error opening directory " << p2p_dir.value() << ": "
<< utils::GetAndFreeGError(&error);
return false;
@@ -327,7 +327,7 @@
string ext_visible = GetExt(kVisible);
string ext_non_visible = GetExt(kNonVisible);
- while ((name = g_dir_read_name(dir)) != NULL) {
+ while ((name = g_dir_read_name(dir)) != nullptr) {
if (!(g_str_has_suffix(name, ext_visible.c_str()) ||
g_str_has_suffix(name, ext_non_visible.c_str())))
continue;
@@ -392,18 +392,18 @@
// the callback is always called from the GLib mainloop (this
// guarantee is useful for testing).
- GError *error = NULL;
- if (!g_spawn_async_with_pipes(NULL, // working_directory
+ GError *error = nullptr;
+ if (!g_spawn_async_with_pipes(nullptr, // working_directory
argv,
- NULL, // envp
+ nullptr, // envp
static_cast<GSpawnFlags>(G_SPAWN_SEARCH_PATH |
G_SPAWN_DO_NOT_REAP_CHILD),
- NULL, // child_setup
+ nullptr, // child_setup
this,
&pid_,
- NULL, // standard_input
+ nullptr, // standard_input
&stdout_fd_,
- NULL, // standard_error
+ nullptr, // standard_error
&error)) {
LOG(ERROR) << "Error spawning p2p-client: "
<< utils::GetAndFreeGError(&error);
@@ -480,12 +480,12 @@
GIOCondition condition,
gpointer user_data) {
LookupData *lookup_data = reinterpret_cast<LookupData*>(user_data);
- gchar* str = NULL;
- GError* error = NULL;
+ gchar* str = nullptr;
+ GError* error = nullptr;
GIOStatus status = g_io_channel_read_line(source,
&str,
- NULL, // len
- NULL, // line_terminator
+ nullptr, // len
+ nullptr, // line_terminator
&error);
if (status != G_IO_STATUS_NORMAL) {
// Ignore EOF since we usually get that before SIGCHLD and we
@@ -497,7 +497,7 @@
delete lookup_data;
}
} else {
- if (str != NULL) {
+ if (str != nullptr) {
lookup_data->stdout_ += str;
g_free(str);
}
@@ -660,7 +660,7 @@
LOG(ERROR) << "No file for id " << file_id;
return false;
}
- if (out_result != NULL)
+ if (out_result != nullptr)
*out_result = path.MatchesExtension(kP2PExtension);
return true;
}
@@ -716,7 +716,7 @@
return -1;
}
- char* endp = NULL;
+ char* endp = nullptr;
long long int val = strtoll(ea_value, &endp, 0); // NOLINT(runtime/int)
if (*endp != '\0') {
LOG(ERROR) << "Error parsing the value '" << ea_value
@@ -730,13 +730,13 @@
int P2PManagerImpl::CountSharedFiles() {
GDir* dir;
- GError* error = NULL;
+ GError* error = nullptr;
const char* name;
int num_files = 0;
base::FilePath p2p_dir = configuration_->GetP2PDir();
dir = g_dir_open(p2p_dir.value().c_str(), 0, &error);
- if (dir == NULL) {
+ if (dir == nullptr) {
LOG(ERROR) << "Error opening directory " << p2p_dir.value() << ": "
<< utils::GetAndFreeGError(&error);
return -1;
@@ -744,7 +744,7 @@
string ext_visible = GetExt(kVisible);
string ext_non_visible = GetExt(kNonVisible);
- while ((name = g_dir_read_name(dir)) != NULL) {
+ while ((name = g_dir_read_name(dir)) != nullptr) {
if (g_str_has_suffix(name, ext_visible.c_str()) ||
g_str_has_suffix(name, ext_non_visible.c_str())) {
num_files += 1;