[adb] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.
Test: m
Bug: 68236239
Change-Id: Ia8c4deacafed2f3b7dbc3d4c3c77c6c632e3de81
diff --git a/adb/client/adb_client.cpp b/adb/client/adb_client.cpp
index 849a6e7..1959258 100644
--- a/adb/client/adb_client.cpp
+++ b/adb/client/adb_client.cpp
@@ -46,7 +46,7 @@
#include "sysdeps/chrono.h"
static TransportType __adb_transport = kTransportAny;
-static const char* __adb_serial = NULL;
+static const char* __adb_serial = nullptr;
static TransportId __adb_transport_id = 0;
static const char* __adb_server_socket_spec;
diff --git a/adb/client/auth.cpp b/adb/client/auth.cpp
index 0f4dd33..5fbef09 100644
--- a/adb/client/auth.cpp
+++ b/adb/client/auth.cpp
@@ -109,7 +109,7 @@
LOG(INFO) << "generate_key(" << file << ")...";
mode_t old_mask;
- FILE *f = NULL;
+ FILE *f = nullptr;
int ret = 0;
EVP_PKEY* pkey = EVP_PKEY_new();
@@ -121,7 +121,7 @@
}
BN_set_word(exponent, RSA_F4);
- RSA_generate_key_ex(rsa, 2048, exponent, NULL);
+ RSA_generate_key_ex(rsa, 2048, exponent, nullptr);
EVP_PKEY_set1_RSA(pkey, rsa);
old_mask = umask(077);
@@ -135,7 +135,7 @@
umask(old_mask);
- if (!PEM_write_PrivateKey(f, pkey, NULL, NULL, 0, NULL, NULL)) {
+ if (!PEM_write_PrivateKey(f, pkey, nullptr, nullptr, 0, nullptr, nullptr)) {
D("Failed to write key");
goto out;
}
@@ -302,7 +302,7 @@
static std::string adb_auth_sign(RSA* key, const char* token, size_t token_size) {
if (token_size != TOKEN_SIZE) {
D("Unexpected token size %zd", token_size);
- return 0;
+ return nullptr;
}
std::string result;
diff --git a/adb/client/commandline.cpp b/adb/client/commandline.cpp
index e07dba7..80d0dd3 100644
--- a/adb/client/commandline.cpp
+++ b/adb/client/commandline.cpp
@@ -885,7 +885,7 @@
return 0;
}
- int block = strtol(buf, NULL, 10);
+ int block = strtol(buf, nullptr, 10);
size_t offset = block * SIDELOAD_HOST_BLOCK_SIZE;
if (offset >= static_cast<size_t>(sb.st_size)) {
@@ -968,7 +968,7 @@
//argv[2] and beyond become ppp_args[1] and beyond
ppp_args[i - 1] = argv[i];
}
- ppp_args[i-1] = NULL;
+ ppp_args[i-1] = nullptr;
// child side
@@ -1174,7 +1174,7 @@
argv[i++] = argv[j++];
}
argc -= 2;
- argv[argc] = NULL;
+ argv[argc] = nullptr;
}
}
@@ -1969,7 +1969,7 @@
char* end = strrchr(buf, ']');
if (start && end) {
*end = '\0';
- session_id = strtol(start + 1, NULL, 10);
+ session_id = strtol(start + 1, nullptr, 10);
}
}
if (session_id < 0) {
diff --git a/adb/client/line_printer.cpp b/adb/client/line_printer.cpp
index 64d10b6..9758526 100644
--- a/adb/client/line_printer.cpp
+++ b/adb/client/line_printer.cpp
@@ -52,7 +52,7 @@
// MSDN says: "For some systems, [_IOLBF] provides line
// buffering. However, for Win32, the behavior is the same as _IOFBF
// - Full Buffering."
- setvbuf(stdout, NULL, _IONBF, 0);
+ setvbuf(stdout, nullptr, _IONBF, 0);
console_ = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
smart_terminal_ = GetConsoleScreenBufferInfo(console_, &csbi);
diff --git a/adb/client/main.cpp b/adb/client/main.cpp
index 44ed3a2..de6c723 100644
--- a/adb/client/main.cpp
+++ b/adb/client/main.cpp
@@ -89,10 +89,10 @@
// unbuffer stdout and stderr just like if we were run at the console.
// This also keeps stderr unbuffered when it is redirected to adb.log.
if (is_daemon) {
- if (setvbuf(stdout, NULL, _IONBF, 0) == -1) {
+ if (setvbuf(stdout, nullptr, _IONBF, 0) == -1) {
fatal("cannot make stdout unbuffered: %s", strerror(errno));
}
- if (setvbuf(stderr, NULL, _IONBF, 0) == -1) {
+ if (setvbuf(stderr, nullptr, _IONBF, 0) == -1) {
fatal("cannot make stderr unbuffered: %s", strerror(errno));
}
}
diff --git a/adb/client/usb_linux.cpp b/adb/client/usb_linux.cpp
index 1f376a4..76f5d78 100644
--- a/adb/client/usb_linux.cpp
+++ b/adb/client/usb_linux.cpp
@@ -128,7 +128,7 @@
if (!bus_dir) return;
dirent* de;
- while ((de = readdir(bus_dir.get())) != 0) {
+ while ((de = readdir(bus_dir.get())) != nullptr) {
if (contains_non_digit(de->d_name)) continue;
std::string bus_name = base + "/" + de->d_name;
diff --git a/adb/client/usb_windows.cpp b/adb/client/usb_windows.cpp
index f529e8f..026703d 100644
--- a/adb/client/usb_windows.cpp
+++ b/adb/client/usb_windows.cpp
@@ -126,11 +126,11 @@
int usb_close(usb_handle* handle);
int known_device_locked(const wchar_t* dev_name) {
- if (NULL != dev_name) {
+ if (nullptr != dev_name) {
// Iterate through the list looking for the name match.
for (usb_handle* usb : handle_list) {
// In Windows names are not case sensetive!
- if ((NULL != usb->interface_name) && (0 == wcsicmp(usb->interface_name, dev_name))) {
+ if ((nullptr != usb->interface_name) && (0 == wcsicmp(usb->interface_name, dev_name))) {
return 1;
}
}
@@ -142,7 +142,7 @@
int known_device(const wchar_t* dev_name) {
int ret = 0;
- if (NULL != dev_name) {
+ if (nullptr != dev_name) {
std::lock_guard<std::mutex> lock(usb_lock);
ret = known_device_locked(dev_name);
}
@@ -151,7 +151,7 @@
}
int register_new_device(usb_handle* handle) {
- if (NULL == handle) return 0;
+ if (nullptr == handle) return 0;
std::lock_guard<std::mutex> lock(usb_lock);
@@ -209,7 +209,7 @@
// Get the HINSTANCE corresponding to the module that _power_window_proc
// is in (the main module).
- const HINSTANCE instance = GetModuleHandleW(NULL);
+ const HINSTANCE instance = GetModuleHandleW(nullptr);
if (!instance) {
// This is such a common API call that this should never fail.
fatal("GetModuleHandleW failed: %s",
@@ -228,14 +228,14 @@
}
if (!CreateWindowExW(WS_EX_NOACTIVATE, kPowerNotificationWindowClassName,
- L"ADB Power Notification Window", WS_POPUP, 0, 0, 0, 0, NULL, NULL,
- instance, NULL)) {
+ L"ADB Power Notification Window", WS_POPUP, 0, 0, 0, 0, nullptr, nullptr,
+ instance, nullptr)) {
fatal("CreateWindowExW failed: %s",
android::base::SystemErrorCodeToString(GetLastError()).c_str());
}
MSG msg;
- while (GetMessageW(&msg, NULL, 0, 0)) {
+ while (GetMessageW(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
@@ -259,14 +259,14 @@
// Allocate our handle
usb_handle* ret = (usb_handle*)calloc(1, sizeof(usb_handle));
- if (NULL == ret) {
+ if (nullptr == ret) {
D("Could not allocate %u bytes for usb_handle: %s", sizeof(usb_handle), strerror(errno));
goto fail;
}
// Create interface.
ret->adb_interface = AdbCreateInterfaceByName(interface_name);
- if (NULL == ret->adb_interface) {
+ if (nullptr == ret->adb_interface) {
D("AdbCreateInterfaceByName failed: %s",
android::base::SystemErrorCodeToString(GetLastError()).c_str());
goto fail;
@@ -275,7 +275,7 @@
// Open read pipe (endpoint)
ret->adb_read_pipe = AdbOpenDefaultBulkReadEndpoint(
ret->adb_interface, AdbOpenAccessTypeReadWrite, AdbOpenSharingModeReadWrite);
- if (NULL == ret->adb_read_pipe) {
+ if (nullptr == ret->adb_read_pipe) {
D("AdbOpenDefaultBulkReadEndpoint failed: %s",
android::base::SystemErrorCodeToString(GetLastError()).c_str());
goto fail;
@@ -284,7 +284,7 @@
// Open write pipe (endpoint)
ret->adb_write_pipe = AdbOpenDefaultBulkWriteEndpoint(
ret->adb_interface, AdbOpenAccessTypeReadWrite, AdbOpenSharingModeReadWrite);
- if (NULL == ret->adb_write_pipe) {
+ if (nullptr == ret->adb_write_pipe) {
D("AdbOpenDefaultBulkWriteEndpoint failed: %s",
android::base::SystemErrorCodeToString(GetLastError()).c_str());
goto fail;
@@ -292,7 +292,7 @@
// Save interface name
// First get expected name length
- AdbGetInterfaceName(ret->adb_interface, NULL, &name_len, false);
+ AdbGetInterfaceName(ret->adb_interface, nullptr, &name_len, false);
if (0 == name_len) {
D("AdbGetInterfaceName returned name length of zero: %s",
android::base::SystemErrorCodeToString(GetLastError()).c_str());
@@ -300,7 +300,7 @@
}
ret->interface_name = (wchar_t*)malloc(name_len * sizeof(ret->interface_name[0]));
- if (NULL == ret->interface_name) {
+ if (nullptr == ret->interface_name) {
D("Could not allocate %lu characters for interface_name: %s", name_len, strerror(errno));
goto fail;
}
@@ -316,12 +316,12 @@
return ret;
fail:
- if (NULL != ret) {
+ if (nullptr != ret) {
usb_cleanup_handle(ret);
free(ret);
}
- return NULL;
+ return nullptr;
}
int usb_write(usb_handle* handle, const void* data, int len) {
@@ -330,7 +330,7 @@
int err = 0;
D("usb_write %d", len);
- if (NULL == handle) {
+ if (nullptr == handle) {
D("usb_write was passed NULL handle");
err = EINVAL;
goto fail;
@@ -370,7 +370,7 @@
fail:
// Any failure should cause us to kick the device instead of leaving it a
// zombie state with potential to hang.
- if (NULL != handle) {
+ if (nullptr != handle) {
D("Kicking device due to error in usb_write");
usb_kick(handle);
}
@@ -387,7 +387,7 @@
int orig_len = len;
D("usb_read %d", len);
- if (NULL == handle) {
+ if (nullptr == handle) {
D("usb_read was passed NULL handle");
err = EINVAL;
goto fail;
@@ -411,7 +411,7 @@
fail:
// Any failure should cause us to kick the device instead of leaving it a
// zombie state with potential to hang.
- if (NULL != handle) {
+ if (nullptr != handle) {
D("Kicking device due to error in usb_read");
usb_kick(handle);
}
@@ -431,19 +431,19 @@
void usb_cleanup_handle(usb_handle* handle) {
D("usb_cleanup_handle");
- if (NULL != handle) {
- if (NULL != handle->interface_name) free(handle->interface_name);
+ if (nullptr != handle) {
+ if (nullptr != handle->interface_name) free(handle->interface_name);
// AdbCloseHandle(pipe) will break any threads out of pending IO calls and
// wait until the pipe no longer uses the interface. Then we can
// AdbCloseHandle() the interface.
- if (NULL != handle->adb_write_pipe) _adb_close_handle(handle->adb_write_pipe);
- if (NULL != handle->adb_read_pipe) _adb_close_handle(handle->adb_read_pipe);
- if (NULL != handle->adb_interface) _adb_close_handle(handle->adb_interface);
+ if (nullptr != handle->adb_write_pipe) _adb_close_handle(handle->adb_write_pipe);
+ if (nullptr != handle->adb_read_pipe) _adb_close_handle(handle->adb_read_pipe);
+ if (nullptr != handle->adb_interface) _adb_close_handle(handle->adb_interface);
- handle->interface_name = NULL;
- handle->adb_write_pipe = NULL;
- handle->adb_read_pipe = NULL;
- handle->adb_interface = NULL;
+ handle->interface_name = nullptr;
+ handle->adb_write_pipe = nullptr;
+ handle->adb_read_pipe = nullptr;
+ handle->adb_interface = nullptr;
}
}
@@ -455,7 +455,7 @@
void usb_kick(usb_handle* handle) {
D("usb_kick");
- if (NULL != handle) {
+ if (nullptr != handle) {
std::lock_guard<std::mutex> lock(usb_lock);
usb_kick_locked(handle);
} else {
@@ -466,7 +466,7 @@
int usb_close(usb_handle* handle) {
D("usb_close");
- if (NULL != handle) {
+ if (nullptr != handle) {
// Remove handle from the list
{
std::lock_guard<std::mutex> lock(usb_lock);
@@ -487,7 +487,7 @@
}
int recognized_device(usb_handle* handle) {
- if (NULL == handle) return 0;
+ if (nullptr == handle) return 0;
// Check vendor and product id first
USB_DEVICE_DESCRIPTOR device_desc;
@@ -532,7 +532,7 @@
}
void find_devices() {
- usb_handle* handle = NULL;
+ usb_handle* handle = nullptr;
char entry_buffer[2048];
AdbInterfaceInfo* next_interface = (AdbInterfaceInfo*)(&entry_buffer[0]);
unsigned long entry_buffer_size = sizeof(entry_buffer);
@@ -540,7 +540,7 @@
// Enumerate all present and active interfaces.
ADBAPIHANDLE enum_handle = AdbEnumInterfaces(usb_class_id, true, true, true);
- if (NULL == enum_handle) {
+ if (nullptr == enum_handle) {
D("AdbEnumInterfaces failed: %s",
android::base::SystemErrorCodeToString(GetLastError()).c_str());
return;
@@ -551,7 +551,7 @@
if (!known_device(next_interface->device_name)) {
// This seems to be a new device. Open it!
handle = do_usb_open(next_interface->device_name);
- if (NULL != handle) {
+ if (nullptr != handle) {
// Lets see if this interface (device) belongs to us
if (recognized_device(handle)) {
D("adding a new device %ls", next_interface->device_name);
@@ -569,7 +569,7 @@
true)) {
// Lets make sure that we don't duplicate this device
if (register_new_device(handle)) {
- register_usb_transport(handle, serial_number, NULL, 1);
+ register_usb_transport(handle, serial_number, nullptr, 1);
} else {
D("register_new_device failed for %ls", next_interface->device_name);
usb_cleanup_handle(handle);