Commit 1750cbd2 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Shorten many "ptr != nullptr" checks in various chrome/ subdirs.

For instance, if (ptr != nullptr) can just become if (ptr).

Change-Id: I56fc1a8f97d72f46bca8035e3bcb9b4fae199b1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2227114Reviewed-by: default avatarDavid Bienvenu <davidbienvenu@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774357}
parent 1f579fd3
...@@ -173,9 +173,8 @@ void GetExtensionSettingsPoliciesFromParsedJson( ...@@ -173,9 +173,8 @@ void GetExtensionSettingsPoliciesFromParsedJson(
if (settings_value->is_dict()) { if (settings_value->is_dict()) {
base::Value* installation_mode = base::Value* installation_mode =
settings_value->FindKey(kExtensionSettingsInstallationModeName); settings_value->FindKey(kExtensionSettingsInstallationModeName);
if (installation_mode != nullptr && if (installation_mode && installation_mode->GetString() ==
installation_mode->GetString() == kExtensionSettingsForceInstalledValue) {
kExtensionSettingsForceInstalledValue) {
policies->emplace_back( policies->emplace_back(
extension_id, registry_key.hkey, registry_key.path, extension_id, registry_key.hkey, registry_key.path,
kExtensionSettingsRegistryEntryName, type, saved_json); kExtensionSettingsRegistryEntryName, type, saved_json);
......
...@@ -143,7 +143,7 @@ SandboxChildProcess::GetCleanerEngineRequestsProxy() { ...@@ -143,7 +143,7 @@ SandboxChildProcess::GetCleanerEngineRequestsProxy() {
void SandboxChildProcess::UnbindRequestsRemotes() { void SandboxChildProcess::UnbindRequestsRemotes() {
base::SingleThreadTaskExecutor main_task_executor; base::SingleThreadTaskExecutor main_task_executor;
base::RunLoop run_loop; base::RunLoop run_loop;
if (GetCleanerEngineRequestsProxy() != nullptr) { if (GetCleanerEngineRequestsProxy()) {
mojo_task_runner_->PostTask( mojo_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&CleanerEngineRequestsProxy::UnbindRequestsRemote, base::BindOnce(&CleanerEngineRequestsProxy::UnbindRequestsRemote,
......
...@@ -172,7 +172,7 @@ ResultCode SandboxTargetHooks::TargetStartedWithHighPrivileges() { ...@@ -172,7 +172,7 @@ ResultCode SandboxTargetHooks::TargetStartedWithHighPrivileges() {
SandboxType SandboxProcessType() { SandboxType SandboxProcessType() {
// This should only be called by children processes. // This should only be called by children processes.
DCHECK(sandbox::SandboxFactory::GetTargetServices() != nullptr); DCHECK(sandbox::SandboxFactory::GetTargetServices());
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
int val = -1; int val = -1;
......
...@@ -78,7 +78,7 @@ UwS PUPToUwS(const PUPData::PUP* found_uws, ...@@ -78,7 +78,7 @@ UwS PUPToUwS(const PUPData::PUP* found_uws,
UwS detected_uws; UwS detected_uws;
detected_uws.set_id(found_signature.id); detected_uws.set_id(found_signature.id);
if (found_signature.name != nullptr) if (found_signature.name)
detected_uws.set_name(found_signature.name); detected_uws.set_name(found_signature.name);
UwS::DetailLevel* detail_level = detected_uws.mutable_detail_level(); UwS::DetailLevel* detail_level = detected_uws.mutable_detail_level();
bool only_one_footprint = (flags & kUwSDetectedFlagsOnlyOneFootprint) != 0; bool only_one_footprint = (flags & kUwSDetectedFlagsOnlyOneFootprint) != 0;
......
...@@ -68,8 +68,7 @@ TEST(FilePathSanitizationTests, SanitizePathConsistency) { ...@@ -68,8 +68,7 @@ TEST(FilePathSanitizationTests, SanitizePathConsistency) {
// rules work correctly. In particular this test verifies each rule is not // rules work correctly. In particular this test verifies each rule is not
// masked by another. // masked by another.
base::FilePath arbitrary_path = NormalizePath(base::FilePath(L"Desktop.ini")); base::FilePath arbitrary_path = NormalizePath(base::FilePath(L"Desktop.ini"));
for (auto* rule = sanitization_internal::rewrite_rules; rule->path != nullptr; for (auto* rule = sanitization_internal::rewrite_rules; rule->path; ++rule) {
++rule) {
base::FilePath expanded_path; base::FilePath expanded_path;
base::PathService::Get(rule->id, &expanded_path); base::PathService::Get(rule->id, &expanded_path);
expanded_path = expanded_path.Append(arbitrary_path); expanded_path = expanded_path.Append(arbitrary_path);
...@@ -133,8 +132,7 @@ TEST(FilePathSanitizationTests, SanitizeCommandLine) { ...@@ -133,8 +132,7 @@ TEST(FilePathSanitizationTests, SanitizeCommandLine) {
TEST(FilePathSanitizationTests, ExpandSpecialFolderPath) { TEST(FilePathSanitizationTests, ExpandSpecialFolderPath) {
base::FilePath arbitrary_path(L"Desktop.ini"); base::FilePath arbitrary_path(L"Desktop.ini");
for (auto* rule = sanitization_internal::rewrite_rules; rule->path != nullptr; for (auto* rule = sanitization_internal::rewrite_rules; rule->path; ++rule) {
++rule) {
// Skip non-CSIDL entries. // Skip non-CSIDL entries.
if (rule->id < sanitization_internal::PATH_CSIDL_START || if (rule->id < sanitization_internal::PATH_CSIDL_START ||
rule->id >= sanitization_internal::PATH_CSIDL_END) { rule->id >= sanitization_internal::PATH_CSIDL_END) {
......
...@@ -77,7 +77,7 @@ class PUPDataTest : public testing::Test { ...@@ -77,7 +77,7 @@ class PUPDataTest : public testing::Test {
const PUPData::StaticDiskFootprint* footprints, const PUPData::StaticDiskFootprint* footprints,
const PUPData::StaticDiskFootprint& footprint) { const PUPData::StaticDiskFootprint& footprint) {
ASSERT_NE(nullptr, footprints); ASSERT_NE(nullptr, footprints);
for (size_t i = 0; footprints[i].path != nullptr; ++i) { for (size_t i = 0; footprints[i].path; ++i) {
if (footprint.csidl == footprints[i].csidl && if (footprint.csidl == footprints[i].csidl &&
base::FilePath::CompareEqualIgnoreCase(footprints[i].path, base::FilePath::CompareEqualIgnoreCase(footprints[i].path,
footprint.path)) { footprint.path)) {
...@@ -93,7 +93,7 @@ class PUPDataTest : public testing::Test { ...@@ -93,7 +93,7 @@ class PUPDataTest : public testing::Test {
const PUPData::StaticRegistryFootprint* footprints, const PUPData::StaticRegistryFootprint* footprints,
const PUPData::StaticRegistryFootprint& footprint) { const PUPData::StaticRegistryFootprint& footprint) {
ASSERT_NE(nullptr, footprints); ASSERT_NE(nullptr, footprints);
for (size_t i = 0; footprints[i].key_path != nullptr; ++i) { for (size_t i = 0; footprints[i].key_path; ++i) {
if (RegistryFootprintMatch(footprints[i], footprint)) if (RegistryFootprintMatch(footprints[i], footprint))
return; return;
} }
...@@ -163,8 +163,7 @@ class PUPDataTest : public testing::Test { ...@@ -163,8 +163,7 @@ class PUPDataTest : public testing::Test {
if (footprint1.value_name == nullptr || footprint2.value_name == nullptr) if (footprint1.value_name == nullptr || footprint2.value_name == nullptr)
return false; return false;
// If one has a nullptr |value_substring|, the other one should too. // If one has a nullptr |value_substring|, the other one should too.
if ((footprint1.value_substring != nullptr || if ((footprint1.value_substring || footprint2.value_substring) &&
footprint2.value_substring != nullptr) &&
(footprint1.value_substring == nullptr || (footprint1.value_substring == nullptr ||
footprint2.value_substring == nullptr)) { footprint2.value_substring == nullptr)) {
return false; return false;
...@@ -190,7 +189,7 @@ class PUPDataTest : public testing::Test { ...@@ -190,7 +189,7 @@ class PUPDataTest : public testing::Test {
// Compute the size of a StaticDiskFootprint C Array. // Compute the size of a StaticDiskFootprint C Array.
size_t DiskFootprintsSize(const PUPData::StaticDiskFootprint* footprints) { size_t DiskFootprintsSize(const PUPData::StaticDiskFootprint* footprints) {
size_t i = 0; size_t i = 0;
for (; footprints[i].path != nullptr; ++i) { for (; footprints[i].path; ++i) {
} }
return i; return i;
} }
...@@ -199,7 +198,7 @@ class PUPDataTest : public testing::Test { ...@@ -199,7 +198,7 @@ class PUPDataTest : public testing::Test {
size_t RegistryFootprintsSize( size_t RegistryFootprintsSize(
const PUPData::StaticRegistryFootprint* footprints) { const PUPData::StaticRegistryFootprint* footprints) {
size_t i = 0; size_t i = 0;
for (; footprints[i].key_path != nullptr; ++i) { for (; footprints[i].key_path; ++i) {
} }
return i; return i;
} }
...@@ -702,7 +701,7 @@ TEST(SanitizePathVsRawPupDataCsidlTest, TestAllCsidlValues) { ...@@ -702,7 +701,7 @@ TEST(SanitizePathVsRawPupDataCsidlTest, TestAllCsidlValues) {
PUPData::GetPUP(pup_id)->signature(); PUPData::GetPUP(pup_id)->signature();
for (const PUPData::StaticDiskFootprint* disk_footprint = for (const PUPData::StaticDiskFootprint* disk_footprint =
signature.disk_footprints; signature.disk_footprints;
disk_footprint->path != nullptr; disk_footprint->path;
++disk_footprint) { ++disk_footprint) {
int csidl = disk_footprint->csidl; int csidl = disk_footprint->csidl;
if (csidl != PUPData::kInvalidCsidl && if (csidl != PUPData::kInvalidCsidl &&
......
...@@ -17,7 +17,7 @@ String16EmbeddedNulls::String16EmbeddedNulls(const String16EmbeddedNulls& str) = ...@@ -17,7 +17,7 @@ String16EmbeddedNulls::String16EmbeddedNulls(const String16EmbeddedNulls& str) =
String16EmbeddedNulls::String16EmbeddedNulls(const wchar_t* const array, String16EmbeddedNulls::String16EmbeddedNulls(const wchar_t* const array,
size_t size) { size_t size) {
// Empty strings should always be represented as an empty array. // Empty strings should always be represented as an empty array.
if (array != nullptr && size > 0) if (array && size > 0)
data_ = std::vector<wchar_t>(array, array + size); data_ = std::vector<wchar_t>(array, array + size);
} }
......
...@@ -86,11 +86,11 @@ bool InitializeCrashReporting() { ...@@ -86,11 +86,11 @@ bool InitializeCrashReporting() {
// NOTE: This function will be called from DllMain during DLL_PROCESS_DETACH // NOTE: This function will be called from DllMain during DLL_PROCESS_DETACH
// (while we have the loader lock), so do not misbehave. // (while we have the loader lock), so do not misbehave.
void ShutdownCrashReporting() { void ShutdownCrashReporting() {
if (g_crash_reports != nullptr) { if (g_crash_reports) {
g_crash_reports->clear(); g_crash_reports->clear();
delete g_crash_reports; delete g_crash_reports;
} }
if (g_set_unhandled_exception_filter != nullptr) { if (g_set_unhandled_exception_filter) {
delete g_set_unhandled_exception_filter; delete g_set_unhandled_exception_filter;
} }
} }
......
...@@ -245,7 +245,7 @@ IATHook::IATHook() ...@@ -245,7 +245,7 @@ IATHook::IATHook()
iat_thunk_(nullptr) {} iat_thunk_(nullptr) {}
IATHook::~IATHook() { IATHook::~IATHook() {
if (intercept_function_ != nullptr) { if (intercept_function_) {
if (Unhook() != NO_ERROR) { if (Unhook() != NO_ERROR) {
#ifdef _DEBUG #ifdef _DEBUG
assert(false); assert(false);
...@@ -264,8 +264,7 @@ DWORD IATHook::Hook(HMODULE module, ...@@ -264,8 +264,7 @@ DWORD IATHook::Hook(HMODULE module,
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
// Only hook once per object, to ensure unhook. // Only hook once per object, to ensure unhook.
if (intercept_function_ != nullptr || original_function_ != nullptr || if (intercept_function_ || original_function_ || iat_thunk_)
iat_thunk_ != nullptr)
return ERROR_SHARING_VIOLATION; return ERROR_SHARING_VIOLATION;
DWORD winerror = ApplyIATHook(module, imported_from_module, function_name, DWORD winerror = ApplyIATHook(module, imported_from_module, function_name,
......
...@@ -331,7 +331,7 @@ void ProcessRedirection(nt::ROOT_KEY root, ...@@ -331,7 +331,7 @@ void ProcessRedirection(nt::ROOT_KEY root,
static constexpr wchar_t kRedirectBefore[] = L"WOW6432Node\\"; static constexpr wchar_t kRedirectBefore[] = L"WOW6432Node\\";
static constexpr wchar_t kRedirectAfter[] = L"\\WOW6432Node"; static constexpr wchar_t kRedirectAfter[] = L"\\WOW6432Node";
assert(subkey_path != nullptr); assert(subkey_path);
assert(subkey_path->empty() || subkey_path->front() != L'\\'); assert(subkey_path->empty() || subkey_path->front() != L'\\');
assert(subkey_path->empty() || subkey_path->back() != L'\\'); assert(subkey_path->empty() || subkey_path->back() != L'\\');
assert(root != nt::AUTO); assert(root != nt::AUTO);
...@@ -466,7 +466,7 @@ std::wstring ConvertRootKey(nt::ROOT_KEY root) { ...@@ -466,7 +466,7 @@ std::wstring ConvertRootKey(nt::ROOT_KEY root) {
// but any other printable character can be used. Value names and data can // but any other printable character can be used. Value names and data can
// include the backslash character." // include the backslash character."
void SanitizeSubkeyPath(std::wstring* input) { void SanitizeSubkeyPath(std::wstring* input) {
assert(input != nullptr); assert(input);
// Remove trailing backslashes. // Remove trailing backslashes.
size_t last_valid_pos = input->find_last_not_of(L'\\'); size_t last_valid_pos = input->find_last_not_of(L'\\');
...@@ -629,7 +629,7 @@ bool CreateRegKey(ROOT_KEY root, ...@@ -629,7 +629,7 @@ bool CreateRegKey(ROOT_KEY root,
HANDLE* out_handle OPTIONAL) { HANDLE* out_handle OPTIONAL) {
// |key_path| can be null or empty, but it can't be longer than // |key_path| can be null or empty, but it can't be longer than
// |g_kRegMaxPathLen| at this point. // |g_kRegMaxPathLen| at this point.
if (key_path != nullptr && if (key_path &&
::wcsnlen(key_path, g_kRegMaxPathLen + 1) == g_kRegMaxPathLen + 1) ::wcsnlen(key_path, g_kRegMaxPathLen + 1) == g_kRegMaxPathLen + 1)
return false; return false;
...@@ -720,7 +720,7 @@ bool OpenRegKey(ROOT_KEY root, ...@@ -720,7 +720,7 @@ bool OpenRegKey(ROOT_KEY root,
NTSTATUS* error_code OPTIONAL) { NTSTATUS* error_code OPTIONAL) {
// |key_path| can be null or empty, but it can't be longer than // |key_path| can be null or empty, but it can't be longer than
// |g_kRegMaxPathLen| at this point. // |g_kRegMaxPathLen| at this point.
if (key_path != nullptr && if (key_path &&
::wcsnlen(key_path, g_kRegMaxPathLen + 1) == g_kRegMaxPathLen + 1) ::wcsnlen(key_path, g_kRegMaxPathLen + 1) == g_kRegMaxPathLen + 1)
return false; return false;
......
...@@ -65,7 +65,7 @@ bool DllMatch(const std::string& module_name) { ...@@ -65,7 +65,7 @@ bool DllMatch(const std::string& module_name) {
if (module_name.empty()) if (module_name.empty())
return false; return false;
for (int i = 0; kDllBlocklist[i] != nullptr; ++i) { for (int i = 0; kDllBlocklist[i]; ++i) {
if (strcmp(module_name.c_str(), kDllBlocklist[i]) == 0) if (strcmp(module_name.c_str(), kDllBlocklist[i]) == 0)
return true; return true;
} }
......
...@@ -122,7 +122,7 @@ base::Version InstallerState::GetCurrentVersion( ...@@ -122,7 +122,7 @@ base::Version InstallerState::GetCurrentVersion(
const ProductState* product_state = const ProductState* product_state =
machine_state.GetProductState(level_ == SYSTEM_LEVEL); machine_state.GetProductState(level_ == SYSTEM_LEVEL);
if (product_state != nullptr) { if (product_state) {
// Be aware that there might be a pending "new_chrome.exe" already in the // Be aware that there might be a pending "new_chrome.exe" already in the
// installation path. If so, we use old_version, which holds the version of // installation path. If so, we use old_version, which holds the version of
// "chrome.exe" itself. // "chrome.exe" itself.
......
...@@ -851,7 +851,7 @@ InstallStatus UninstallProduct(const ModifyParams& modify_params, ...@@ -851,7 +851,7 @@ InstallStatus UninstallProduct(const ModifyParams& modify_params,
const ProductState* const product_state = const ProductState* const product_state =
original_state.GetProductState(installer_state.system_install()); original_state.GetProductState(installer_state.system_install());
if (product_state != nullptr) { if (product_state) {
VLOG(1) << "version on the system: " VLOG(1) << "version on the system: "
<< product_state->version().GetString(); << product_state->version().GetString();
} else if (!force_uninstall) { } else if (!force_uninstall) {
......
...@@ -35,7 +35,7 @@ bool Configuration::Initialize(HMODULE module) { ...@@ -35,7 +35,7 @@ bool Configuration::Initialize(HMODULE module) {
} }
void Configuration::Clear() { void Configuration::Clear() {
if (args_ != nullptr) { if (args_) {
::LocalFree(args_); ::LocalFree(args_);
args_ = nullptr; args_ = nullptr;
} }
......
...@@ -63,7 +63,7 @@ LONG RegKey::WriteDWValue(const wchar_t* value_name, DWORD value) { ...@@ -63,7 +63,7 @@ LONG RegKey::WriteDWValue(const wchar_t* value_name, DWORD value) {
} }
void RegKey::Close() { void RegKey::Close() {
if (key_ != nullptr) { if (key_) {
::RegCloseKey(key_); ::RegCloseKey(key_);
key_ = nullptr; key_ = nullptr;
} }
......
...@@ -18,11 +18,11 @@ HRESULT GetProcessUser(base::string16* name, ...@@ -18,11 +18,11 @@ HRESULT GetProcessUser(base::string16* name,
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
if (sid != nullptr) if (sid)
*sid = current_sid.Sid(); *sid = current_sid.Sid();
if (name != nullptr) if (name)
*name = current_sid.AccountName(); *name = current_sid.AccountName();
if (domain != nullptr) if (domain)
*domain = current_sid.Domain(); *domain = current_sid.Domain();
return S_OK; return S_OK;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment