Skip to content

Commit

Permalink
Convert NULL to nullptr
Browse files Browse the repository at this point in the history
https://google.github.io/styleguide/cppguide.html#0_and_nullptr/NULL
says:
"For pointers (address values), use nullptr, as this provides
type-safety."

Furthermore, NULL/0 won't compile if we change |SomeClass*| to
|CheckedPtr<SomeClass>|. See go/miracleptr for more details.

Bug: 1080832
Change-Id: I8534ad5e03624700692521a76413acf0e020adae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462965
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Bartek Nowierski <bartekn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816055}
  • Loading branch information
Keishi Hattori authored and Commit Bot committed Oct 12, 2020
1 parent 4ec407f commit d837ccb
Show file tree
Hide file tree
Showing 26 changed files with 50 additions and 55 deletions.
4 changes: 2 additions & 2 deletions base/debug/close_handle_hook_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace {
class AutoProtectMemory {
public:
AutoProtectMemory()
: changed_(false), address_(NULL), bytes_(0), old_protect_(0) {}
: changed_(false), address_(nullptr), bytes_(0), old_protect_(0) {}

~AutoProtectMemory() {
RevertProtection();
Expand Down Expand Up @@ -122,7 +122,7 @@ void AutoProtectMemory::RevertProtection() {

VirtualProtect(address_, bytes_, old_protect_, &old_protect_);
changed_ = false;
address_ = NULL;
address_ = nullptr;
bytes_ = 0;
old_protect_ = 0;
}
Expand Down
7 changes: 3 additions & 4 deletions base/files/memory_mapped_file_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

namespace base {

MemoryMappedFile::MemoryMappedFile() : data_(NULL), length_(0) {
}
MemoryMappedFile::MemoryMappedFile() : data_(nullptr), length_(0) {}

bool MemoryMappedFile::MapImageToMemory(Access access) {
ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK);
Expand Down Expand Up @@ -124,7 +123,7 @@ bool MemoryMappedFile::MapFileRegionToMemory(
::MapViewOfFile(file_mapping_.Get(),
(flags & PAGE_READONLY) ? FILE_MAP_READ : FILE_MAP_WRITE,
map_start.HighPart, map_start.LowPart, map_size));
if (data_ == NULL)
if (data_ == nullptr)
return false;
data_ += data_offset;
return true;
Expand All @@ -138,7 +137,7 @@ void MemoryMappedFile::CloseHandles() {
if (file_.IsValid())
file_.Close();

data_ = NULL;
data_ = nullptr;
length_ = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions base/synchronization/waitable_event_watcher_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool WaitableEventWatcher::StartWatching(

void WaitableEventWatcher::StopWatching() {
callback_.Reset();
event_ = NULL;
event_ = nullptr;
watcher_.StopWatching();
duplicated_event_handle_.Close();
}
Expand All @@ -51,7 +51,7 @@ void WaitableEventWatcher::OnObjectSignaled(HANDLE h) {
DCHECK_EQ(duplicated_event_handle_.Get(), h);
WaitableEvent* event = event_;
EventCallback callback = std::move(callback_);
event_ = NULL;
event_ = nullptr;
duplicated_event_handle_.Close();
DCHECK(event);

Expand Down
2 changes: 1 addition & 1 deletion chrome/app/main_dll_loader_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int MainDllLoader::Launch(HINSTANCE instance,
process_type_ = cmd_line.GetSwitchValueASCII(switches::kProcessType);

// Initialize the sandbox services.
sandbox::SandboxInterfaceInfo sandbox_info = {0};
sandbox::SandboxInterfaceInfo sandbox_info = {nullptr};
const bool is_browser = process_type_.empty();
const bool is_cloud_print_service =
process_type_ == switches::kCloudPrintServiceProcess;
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/ui/views/uninstall_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

UninstallView::UninstallView(int* user_selection,
const base::Closure& quit_closure)
: confirm_label_(NULL),
delete_profile_(NULL),
change_default_browser_(NULL),
browsers_combo_(NULL),
: confirm_label_(nullptr),
delete_profile_(nullptr),
change_default_browser_(nullptr),
browsers_combo_(nullptr),
user_selection_(*user_selection),
quit_closure_(quit_closure) {
SetButtonLabel(ui::DIALOG_BUTTON_OK,
Expand Down
5 changes: 2 additions & 3 deletions chrome/test/logging/win/test_log_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,13 @@ TestLogCollector::EventListener::~EventListener() {
// TestLogCollector implementation

TestLogCollector::TestLogCollector()
: unit_test_(NULL), also_emit_success_logs_(false) {
}
: unit_test_(nullptr), also_emit_success_logs_(false) {}

TestLogCollector::~TestLogCollector() {
}

void TestLogCollector::Initialize(testing::UnitTest* unit_test) {
if (unit_test_ != NULL) {
if (unit_test_ != nullptr) {
CHECK_EQ(unit_test, unit_test_)
<< "Cannot install the test log collector in multiple unit tests.";
return; // Already initialized.
Expand Down
2 changes: 1 addition & 1 deletion chrome/utility/importer/nss_decryptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ base::string16 NSSDecryptor::Decrypt(const std::string& crypt) const {
const_cast<char*>(decoded_data.data()));
request.len = static_cast<unsigned int>(decoded_data.size());
SECItem reply;
reply.data = NULL;
reply.data = nullptr;
reply.len = 0;
#if defined(USE_NSS_CERTS)
result = PK11SDR_DecryptWithSlot(slot, &request, &reply, NULL);
Expand Down
24 changes: 12 additions & 12 deletions cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct MonitorData {
};

struct PortData {
PortData() : job_id(0), printer_handle(NULL), file(0) {}
PortData() : job_id(0), printer_handle(NULL), file(nullptr) {}
~PortData() { Close(); }
void Close() {
if (printer_handle) {
Expand All @@ -68,7 +68,7 @@ struct PortData {
}
if (file) {
base::CloseFile(file);
file = NULL;
file = nullptr;
}
}
DWORD job_id;
Expand All @@ -86,18 +86,18 @@ MONITORUI g_monitor_ui = {sizeof(MONITORUI), MonitorUiAddPortUi,
MONITOR2 g_monitor_2 = {sizeof(MONITOR2),
Monitor2EnumPorts,
Monitor2OpenPort,
NULL, // OpenPortEx is not supported.
nullptr, // OpenPortEx is not supported.
Monitor2StartDocPort,
Monitor2WritePort,
Monitor2ReadPort,
Monitor2EndDocPort,
Monitor2ClosePort,
NULL, // AddPort is not supported.
NULL, // AddPortEx is not supported.
NULL, // ConfigurePort is not supported.
NULL, // DeletePort is not supported.
NULL,
NULL, // SetPortTimeOuts is not supported.
nullptr, // AddPort is not supported.
nullptr, // AddPortEx is not supported.
nullptr, // ConfigurePort is not supported.
nullptr, // DeletePort is not supported.
nullptr,
nullptr, // SetPortTimeOuts is not supported.
Monitor2XcvOpenPort,
Monitor2XcvDataPort,
Monitor2XcvClosePort,
Expand Down Expand Up @@ -497,7 +497,7 @@ BOOL WINAPI Monitor2StartDocPort(HANDLE port_handle,
return FALSE;
}
port_data->file = base::OpenFile(file_path, "wb+");
if (port_data->file == NULL) {
if (port_data->file == nullptr) {
LOG(ERROR) << "Error opening file " << file_path.value() << ".";
return FALSE;
}
Expand Down Expand Up @@ -540,9 +540,9 @@ BOOL WINAPI Monitor2EndDocPort(HANDLE port_handle) {
return FALSE;
}

if (port_data->file != NULL) {
if (port_data->file != nullptr) {
base::CloseFile(port_data->file);
port_data->file = NULL;
port_data->file = nullptr;
bool delete_file = true;
int64_t file_size = 0;
base::GetFileSize(port_data->file_path, &file_size);
Expand Down
2 changes: 1 addition & 1 deletion components/nacl/loader/nacl_helper_win_64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int NaClBrokerMain(const content::MainFunctionParams& parameters) {
namespace nacl {

int NaClWin64Main() {
sandbox::SandboxInterfaceInfo sandbox_info = {0};
sandbox::SandboxInterfaceInfo sandbox_info = {nullptr};
content::InitializeSandboxInfo(&sandbox_info);

const base::CommandLine& command_line =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) {
void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) {
if (host_) {
host_->OnLegacyWindowDestroyed();
host_ = NULL;
host_ = nullptr;
}

// Re-enable flicks for just a moment
Expand Down
4 changes: 2 additions & 2 deletions content/browser/renderer_host/render_widget_host_view_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ void RenderWidgetHostViewAura::CopyFromSurface(

#if defined(OS_WIN)
bool RenderWidgetHostViewAura::UsesNativeWindowFrame() const {
return (legacy_render_widget_host_HWND_ != NULL);
return (legacy_render_widget_host_HWND_ != nullptr);
}

void RenderWidgetHostViewAura::UpdateMouseLockRegion() {
Expand Down Expand Up @@ -1694,7 +1694,7 @@ void RenderWidgetHostViewAura::OnWindowDestroying(aura::Window* window) {
legacy_render_widget_host_HWND_->Destroy();
// The Destroy call above will delete the LegacyRenderWidgetHostHWND
// instance.
legacy_render_widget_host_HWND_ = NULL;
legacy_render_widget_host_HWND_ = nullptr;
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion content/public/test/test_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ int LaunchTests(TestLauncherDelegate* launcher_delegate,
#endif

#if defined(OS_WIN)
sandbox::SandboxInterfaceInfo sandbox_info = {0};
sandbox::SandboxInterfaceInfo sandbox_info = {nullptr};
InitializeSandboxInfo(&sandbox_info);

params.instance = GetModuleHandle(NULL);
Expand Down
2 changes: 1 addition & 1 deletion content/shell/app/shell_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main() {
// Load and pin user32.dll to avoid having to load it once tests start while
// on the main thread loop where blocking calls are disallowed.
base::win::PinUser32();
sandbox::SandboxInterfaceInfo sandbox_info = {0};
sandbox::SandboxInterfaceInfo sandbox_info = {nullptr};
content::InitializeSandboxInfo(&sandbox_info);
content::ShellMainDelegate delegate;

Expand Down
2 changes: 1 addition & 1 deletion extensions/shell/app/shell_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) {
extensions::ShellMainDelegate delegate;
content::ContentMainParams params(&delegate);

sandbox::SandboxInterfaceInfo sandbox_info = {0};
sandbox::SandboxInterfaceInfo sandbox_info = {nullptr};
content::InitializeSandboxInfo(&sandbox_info);
params.instance = instance;
params.sandbox_info = &sandbox_info;
Expand Down
2 changes: 1 addition & 1 deletion headless/app/headless_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ int main(int argc, const char** argv) {
#if defined(OS_WIN)
// In windows, you must initialize and set the sandbox, or pass it along
// if it has already been initialized.
sandbox::SandboxInterfaceInfo sandbox_info = {0};
sandbox::SandboxInterfaceInfo sandbox_info = {nullptr};
content::InitializeSandboxInfo(&sandbox_info);
builder.SetSandboxInfo(&sandbox_info);
#endif
Expand Down
2 changes: 1 addition & 1 deletion headless/app/headless_shell_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

int main(int argc, const char** argv) {
#if defined(OS_WIN)
sandbox::SandboxInterfaceInfo sandbox_info = {0};
sandbox::SandboxInterfaceInfo sandbox_info = {nullptr};
content::InitializeSandboxInfo(&sandbox_info);
return headless::HeadlessShellMain(0, &sandbox_info);
#else
Expand Down
2 changes: 1 addition & 1 deletion media/audio/win/audio_low_latency_output_win_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback {
explicit ReadFromFileAudioSource(const std::string& name)
: pos_(0),
previous_call_time_(base::TimeTicks::Now()),
text_file_(NULL),
text_file_(nullptr),
elements_to_write_(0) {
// Reads a test file from media/test/data directory.
file_ = ReadTestDataFile(name);
Expand Down
2 changes: 1 addition & 1 deletion media/audio/win/audio_output_win_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class TestSourceLaggy : public TestSourceBasic {
class ReadOnlyMappedFile {
public:
explicit ReadOnlyMappedFile(const wchar_t* file_name)
: fmap_(NULL), start_(NULL), size_(0) {
: fmap_(NULL), start_(nullptr), size_(0) {
HANDLE file = ::CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE == file)
Expand Down
4 changes: 2 additions & 2 deletions media/audio/win/waveout_output_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ PCMWaveOutAudioOutputStream::PCMWaveOutAudioOutputStream(
UINT device_id)
: state_(PCMA_BRAND_NEW),
manager_(manager),
callback_(NULL),
callback_(nullptr),
num_buffers_(num_buffers),
buffer_size_(params.GetBytesPerBuffer(kSampleFormat)),
volume_(1),
Expand Down Expand Up @@ -270,7 +270,7 @@ void PCMWaveOutAudioOutputStream::Stop() {
GetBuffer(ix)->dwFlags = WHDR_PREPARED;

// Don't use callback after Stop().
callback_ = NULL;
callback_ = nullptr;

state_ = PCMA_READY;
}
Expand Down
6 changes: 3 additions & 3 deletions media/gpu/windows/dxva_video_decode_accelerator_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ DXVAVideoDecodeAccelerator::DXVAVideoDecodeAccelerator(
const gpu::GpuDriverBugWorkarounds& workarounds,
const gpu::GpuPreferences& gpu_preferences,
MediaLog* media_log)
: client_(NULL),
: client_(nullptr),
dev_manager_reset_token_(0),
dx11_dev_manager_reset_token_(0),
egl_config_(NULL),
Expand Down Expand Up @@ -623,7 +623,7 @@ DXVAVideoDecodeAccelerator::DXVAVideoDecodeAccelerator(
}

DXVAVideoDecodeAccelerator::~DXVAVideoDecodeAccelerator() {
client_ = NULL;
client_ = nullptr;
}

bool DXVAVideoDecodeAccelerator::Initialize(const Config& config,
Expand Down Expand Up @@ -1954,7 +1954,7 @@ void DXVAVideoDecodeAccelerator::StopOnError(

if (client_)
client_->NotifyError(error);
client_ = NULL;
client_ = nullptr;

#ifdef _DEBUG
if (using_debug_device_) {
Expand Down
5 changes: 2 additions & 3 deletions sandbox/win/sandbox_poc/main_ui_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ const wchar_t MainUIWindow::kDefaultEntryPoint_[] = L"Run";
const wchar_t MainUIWindow::kDefaultLogFile_[] = L"";

MainUIWindow::MainUIWindow()
: broker_(NULL),
: broker_(nullptr),
spawn_target_(L""),
instance_handle_(NULL),
dll_path_(L""),
entry_point_(L"") {
}
entry_point_(L"") {}

MainUIWindow::~MainUIWindow() {
}
Expand Down
4 changes: 1 addition & 3 deletions sandbox/win/sandbox_poc/pocdll/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
// object goes out of scope
class HandleToFile {
public:
HandleToFile() {
file_ = NULL;
}
HandleToFile() { file_ = nullptr; }

// Note: c_file_handle_ does not need to be closed because fclose does it.
~HandleToFile() {
Expand Down
2 changes: 1 addition & 1 deletion sandbox/win/tests/common/controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ TestRunner::TestRunner(JobLevel job_level,
no_sandbox_(false),
disable_csrss_(true),
target_process_id_(0) {
broker_ = NULL;
broker_ = nullptr;
policy_.reset();
timeout_ = kDefaultTimeout;
state_ = AFTER_REVERT;
Expand Down
2 changes: 1 addition & 1 deletion ui/gfx/win/window_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void WindowImpl::Init(HWND parent, const Rect& bounds) {
CHECK(false);
}
if (!destroyed)
destroyed_ = NULL;
destroyed_ = nullptr;

CheckWindowCreated(hwnd_, create_window_error);

Expand Down
2 changes: 1 addition & 1 deletion ui/views_content_client/views_content_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace ui {
//
// #if defined(OS_WIN)
// int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) {
// sandbox::SandboxInterfaceInfo sandbox_info = {0};
// sandbox::SandboxInterfaceInfo sandbox_info = {nullptr};
// content::InitializeSandboxInfo(&sandbox_info);
// ui::ViewsContentClient params(instance, &sandbox_info);
// #else
Expand Down
2 changes: 1 addition & 1 deletion weblayer/app/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int Main(MainParams params
#if defined(WIN_CONSOLE_APP)
HINSTANCE instance = GetModuleHandle(nullptr);
#endif
sandbox::SandboxInterfaceInfo sandbox_info = {0};
sandbox::SandboxInterfaceInfo sandbox_info = {nullptr};
content::InitializeSandboxInfo(&sandbox_info);
content_params.instance = instance;
content_params.sandbox_info = &sandbox_info;
Expand Down

0 comments on commit d837ccb

Please sign in to comment.