diff --git a/adb/adb.cpp b/adb/adb.cpp index f8a54c6bf..20d0db5fb 100644 --- a/adb/adb.cpp +++ b/adb/adb.cpp @@ -415,7 +415,7 @@ void handle_packet(apacket *p, atransport *t) if (t->online && p->msg.arg0 != 0 && p->msg.arg1 != 0) { asocket* s = find_local_socket(p->msg.arg1, 0); if (s) { - if(s->peer == 0) { + if(s->peer == nullptr) { /* On first READY message, create the connection. */ s->peer = create_remote_socket(p->msg.arg0, t); s->peer->peer = s; diff --git a/adb/adb_io.cpp b/adb/adb_io.cpp index 38e31167e..6cc274bbe 100644 --- a/adb/adb_io.cpp +++ b/adb/adb_io.cpp @@ -49,7 +49,7 @@ bool ReadProtocolString(int fd, std::string* s, std::string* error) { } buf[4] = 0; - unsigned long len = strtoul(buf, 0, 16); + unsigned long len = strtoul(buf, nullptr, 16); s->resize(len, '\0'); if (!ReadFdExactly(fd, &(*s)[0], len)) { *error = perror_str("protocol fault (couldn't read status message)"); diff --git a/adb/client/adb_client.cpp b/adb/client/adb_client.cpp index 849a6e772..1959258b9 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 0f4dd3397..5fbef0994 100644 --- a/adb/client/auth.cpp +++ b/adb/client/auth.cpp @@ -109,7 +109,7 @@ static int generate_key(const std::string& file) { 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 @@ static int generate_key(const std::string& file) { } 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 @@ static int generate_key(const std::string& file) { 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 @@ std::deque> adb_auth_get_private_keys() { 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 e07dba7cf..80d0dd3d1 100644 --- a/adb/client/commandline.cpp +++ b/adb/client/commandline.cpp @@ -885,7 +885,7 @@ static int adb_sideload_host(const char* filename) { 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(sb.st_size)) { @@ -968,7 +968,7 @@ static int ppp(int argc, const char** argv) { //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 @@ static int backup(int argc, const char** argv) { argv[i++] = argv[j++]; } argc -= 2; - argv[argc] = NULL; + argv[argc] = nullptr; } } @@ -1969,7 +1969,7 @@ static int install_multiple_app(int argc, const char** argv) { 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 64d10b6ca..9758526c4 100644 --- a/adb/client/line_printer.cpp +++ b/adb/client/line_printer.cpp @@ -52,7 +52,7 @@ LinePrinter::LinePrinter() : have_blank_line_(true) { // 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 44ed3a253..de6c72332 100644 --- a/adb/client/main.cpp +++ b/adb/client/main.cpp @@ -89,10 +89,10 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply // 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 1f376a4c9..76f5d78d8 100644 --- a/adb/client/usb_linux.cpp +++ b/adb/client/usb_linux.cpp @@ -128,7 +128,7 @@ static void find_usb_device(const std::string& base, 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 f529e8f32..026703d8c 100644 --- a/adb/client/usb_windows.cpp +++ b/adb/client/usb_windows.cpp @@ -126,11 +126,11 @@ void usb_kick(usb_handle* handle); 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_locked(const wchar_t* dev_name) { int known_device(const wchar_t* dev_name) { int ret = 0; - if (NULL != dev_name) { + if (nullptr != dev_name) { std::lock_guard lock(usb_lock); ret = known_device_locked(dev_name); } @@ -151,7 +151,7 @@ int known_device(const wchar_t* dev_name) { } int register_new_device(usb_handle* handle) { - if (NULL == handle) return 0; + if (nullptr == handle) return 0; std::lock_guard lock(usb_lock); @@ -209,7 +209,7 @@ static void _power_notification_thread() { // 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 @@ static void _power_notification_thread() { } 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 @@ usb_handle* do_usb_open(const wchar_t* interface_name) { // 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 @@ usb_handle* do_usb_open(const wchar_t* interface_name) { // 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 @@ usb_handle* do_usb_open(const wchar_t* interface_name) { // 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 @@ usb_handle* do_usb_open(const wchar_t* interface_name) { // 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 @@ usb_handle* do_usb_open(const wchar_t* interface_name) { } 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 @@ usb_handle* do_usb_open(const wchar_t* interface_name) { 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 usb_write(usb_handle* handle, const void* data, int len) { 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 @@ int usb_write(usb_handle* handle, const void* data, int len) { 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 usb_read(usb_handle* handle, void* data, int len) { 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 @@ int usb_read(usb_handle* handle, void* data, int len) { 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 @@ static void _adb_close_handle(ADBAPIHANDLE adb_handle) { 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 @@ static void usb_kick_locked(usb_handle* handle) { void usb_kick(usb_handle* handle) { D("usb_kick"); - if (NULL != handle) { + if (nullptr != handle) { std::lock_guard lock(usb_lock); usb_kick_locked(handle); } else { @@ -466,7 +466,7 @@ void usb_kick(usb_handle* handle) { int usb_close(usb_handle* handle) { D("usb_close"); - if (NULL != handle) { + if (nullptr != handle) { // Remove handle from the list { std::lock_guard lock(usb_lock); @@ -487,7 +487,7 @@ size_t usb_get_max_packet_size(usb_handle* handle) { } 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 @@ int recognized_device(usb_handle* handle) { } 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 @@ void find_devices() { // 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 @@ void find_devices() { 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 @@ void find_devices() { 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); diff --git a/adb/daemon/auth.cpp b/adb/daemon/auth.cpp index f0c36294b..180df8f21 100644 --- a/adb/daemon/auth.cpp +++ b/adb/daemon/auth.cpp @@ -100,7 +100,7 @@ static bool adbd_auth_generate_token(void* token, size_t token_size) { static void usb_disconnected(void* unused, atransport* t) { LOG(INFO) << "USB disconnect"; - usb_transport = NULL; + usb_transport = nullptr; needs_retry = false; } @@ -200,7 +200,7 @@ void adbd_auth_init(void) { return; } - listener_fde = fdevent_create(fd, adbd_auth_listener, NULL); + listener_fde = fdevent_create(fd, adbd_auth_listener, nullptr); fdevent_add(listener_fde, FDE_READ); } diff --git a/adb/daemon/framebuffer_service.cpp b/adb/daemon/framebuffer_service.cpp index 6c3a2252f..20e03f9c7 100644 --- a/adb/daemon/framebuffer_service.cpp +++ b/adb/daemon/framebuffer_service.cpp @@ -75,7 +75,7 @@ void framebuffer_service(int fd, void *cookie) adb_close(fds[0]); adb_close(fds[1]); const char* command = "screencap"; - const char *args[2] = {command, NULL}; + const char *args[2] = {command, nullptr}; execvp(command, (char**)args); exit(1); } @@ -182,7 +182,7 @@ void framebuffer_service(int fd, void *cookie) done: adb_close(fds[0]); - TEMP_FAILURE_RETRY(waitpid(pid, NULL, 0)); + TEMP_FAILURE_RETRY(waitpid(pid, nullptr, 0)); pipefail: adb_close(fd); } diff --git a/adb/daemon/jdwp_service.cpp b/adb/daemon/jdwp_service.cpp index 367695dc6..175e82e8e 100644 --- a/adb/daemon/jdwp_service.cpp +++ b/adb/daemon/jdwp_service.cpp @@ -264,7 +264,7 @@ static void jdwp_process_event(int socket, unsigned events, void* _proc) { iov.iov_base = &dummy; iov.iov_len = 1; - msg.msg_name = NULL; + msg.msg_name = nullptr; msg.msg_namelen = 0; msg.msg_iov = &iov; msg.msg_iovlen = 1; @@ -393,7 +393,7 @@ static int jdwp_control_init(JdwpControl* control, const char* sockname, int soc control->listen_socket = s; control->fde = fdevent_create(s, jdwp_control_event, control); - if (control->fde == NULL) { + if (control->fde == nullptr) { D("could not create fdevent for jdwp control socket"); adb_close(s); return -1; diff --git a/adb/daemon/set_verity_enable_state_service.cpp b/adb/daemon/set_verity_enable_state_service.cpp index 0fcf89b7c..dbeee280d 100644 --- a/adb/daemon/set_verity_enable_state_service.cpp +++ b/adb/daemon/set_verity_enable_state_service.cpp @@ -135,7 +135,7 @@ void set_verity_enabled_state_service(int fd, void* cookie) { unique_fd closer(fd); bool any_changed = false; - bool enable = (cookie != NULL); + bool enable = (cookie != nullptr); // Figure out if we're using VB1.0 or VB2.0 (aka AVB) - by // contract, androidboot.vbmeta.digest is set by the bootloader diff --git a/adb/daemon/usb.cpp b/adb/daemon/usb.cpp index c724b1102..51ad5f5d2 100644 --- a/adb/daemon/usb.cpp +++ b/adb/daemon/usb.cpp @@ -359,7 +359,7 @@ static void usb_ffs_open_thread(void* x) { } LOG(INFO) << "registering usb transport"; - register_usb_transport(usb, 0, 0, 1); + register_usb_transport(usb, nullptr, nullptr, 1); } // never gets here diff --git a/adb/fdevent.cpp b/adb/fdevent.cpp index 098a39dc1..dee87bdf3 100644 --- a/adb/fdevent.cpp +++ b/adb/fdevent.cpp @@ -149,7 +149,7 @@ fdevent* fdevent_create(int fd, fd_func func, void* arg) { void fdevent_destroy(fdevent* fde) { check_main_thread(); - if (fde == 0) return; + if (fde == nullptr) return; if (!(fde->state & FDE_CREATED)) { LOG(FATAL) << "destroying fde not created by fdevent_create(): " << dump_fde(fde); } diff --git a/adb/services.cpp b/adb/services.cpp index a757d9066..1fa7ecc07 100644 --- a/adb/services.cpp +++ b/adb/services.cpp @@ -352,7 +352,7 @@ static void wait_for_state(int fd, void* data) { while (true) { bool is_ambiguous = false; std::string error = "unknown error"; - const char* serial = sinfo->serial.length() ? sinfo->serial.c_str() : NULL; + const char* serial = sinfo->serial.length() ? sinfo->serial.c_str() : nullptr; atransport* t = acquire_one_transport(sinfo->transport_type, serial, sinfo->transport_id, &is_ambiguous, &error); if (t != nullptr && (sinfo->state == kCsAny || sinfo->state == t->GetConnectionState())) { @@ -389,8 +389,8 @@ void connect_emulator(const std::string& port_spec, std::string* response) { return; } - int console_port = strtol(pieces[0].c_str(), NULL, 0); - int adb_port = strtol(pieces[1].c_str(), NULL, 0); + int console_port = strtol(pieces[0].c_str(), nullptr, 0); + int adb_port = strtol(pieces[1].c_str(), nullptr, 0); if (console_port <= 0 || adb_port <= 0) { *response = android::base::StringPrintf("Invalid port numbers: %s", port_spec.c_str()); return; @@ -494,6 +494,6 @@ asocket* host_service_to_socket(const char* name, const char* serial, TransportI } return create_local_socket(fd); } - return NULL; + return nullptr; } #endif /* ADB_HOST */ diff --git a/adb/sockets.cpp b/adb/sockets.cpp index de3215dc4..69b518066 100644 --- a/adb/sockets.cpp +++ b/adb/sockets.cpp @@ -337,7 +337,7 @@ asocket* create_local_socket(int fd) { s->fd = fd; s->enqueue = local_socket_enqueue; s->ready = local_socket_ready; - s->shutdown = NULL; + s->shutdown = nullptr; s->close = local_socket_close; install_local_socket(s); @@ -383,7 +383,7 @@ static asocket* create_host_service_socket(const char* name, const char* serial, s = host_service_to_socket(name, serial, transport_id); - if (s != NULL) { + if (s != nullptr) { D("LS(%d) bound to '%s'", s->id, name); return s; } @@ -435,7 +435,7 @@ static void remote_socket_shutdown(asocket* s) { static void remote_socket_close(asocket* s) { if (s->peer) { - s->peer->peer = 0; + s->peer->peer = nullptr; D("RS(%d) peer->close()ing peer->id=%d peer->fd=%d", s->id, s->peer->id, s->peer->fd); s->peer->close(s->peer); } @@ -488,7 +488,7 @@ void connect_to_remote(asocket* s, const char* destination) { send the go-ahead message when they connect */ static void local_socket_ready_notify(asocket* s) { s->ready = local_socket_ready; - s->shutdown = NULL; + s->shutdown = nullptr; s->close = local_socket_close; SendOkay(s->fd); s->ready(s); @@ -499,7 +499,7 @@ static void local_socket_ready_notify(asocket* s) { connected (to avoid closing them without a status message) */ static void local_socket_close_notify(asocket* s) { s->ready = local_socket_ready; - s->shutdown = NULL; + s->shutdown = nullptr; s->close = local_socket_close; SendFail(s->fd, "closed"); s->close(s); @@ -706,7 +706,7 @@ static int smart_socket_enqueue(asocket* s, apacket::payload_type data) { ** and tear down here. */ s2 = create_host_service_socket(service, serial, transport_id); - if (s2 == 0) { + if (s2 == nullptr) { D("SS(%d): couldn't create host service '%s'", s->id, service); SendFail(s->peer->fd, "unknown host service"); goto fail; @@ -726,7 +726,7 @@ static int smart_socket_enqueue(asocket* s, apacket::payload_type data) { s->peer->close = local_socket_close; s->peer->peer = s2; s2->peer = s->peer; - s->peer = 0; + s->peer = nullptr; D("SS(%d): okay", s->id); s->close(s); @@ -764,12 +764,12 @@ static int smart_socket_enqueue(asocket* s, apacket::payload_type data) { s->peer->ready = local_socket_ready_notify; s->peer->shutdown = nullptr; s->peer->close = local_socket_close_notify; - s->peer->peer = 0; + s->peer->peer = nullptr; /* give him our transport and upref it */ s->peer->transport = s->transport; connect_to_remote(s->peer, s->smart_socket_data.data() + 4); - s->peer = 0; + s->peer = nullptr; s->close(s); return 1; @@ -789,9 +789,9 @@ static void smart_socket_ready(asocket* s) { static void smart_socket_close(asocket* s) { D("SS(%d): closed", s->id); if (s->peer) { - s->peer->peer = 0; + s->peer->peer = nullptr; s->peer->close(s->peer); - s->peer = 0; + s->peer = nullptr; } delete s; } @@ -801,7 +801,7 @@ static asocket* create_smart_socket(void) { asocket* s = new asocket(); s->enqueue = smart_socket_enqueue; s->ready = smart_socket_ready; - s->shutdown = NULL; + s->shutdown = nullptr; s->close = smart_socket_close; D("SS(%d)", s->id); diff --git a/adb/sysdeps_win32.cpp b/adb/sysdeps_win32.cpp index 52f586ca2..c94d13f96 100644 --- a/adb/sysdeps_win32.cpp +++ b/adb/sysdeps_win32.cpp @@ -158,7 +158,7 @@ _fh_from_int( int fd, const char* func ) D( "_fh_from_int: invalid fd %d passed to %s", fd + WIN32_FH_BASE, func ); errno = EBADF; - return NULL; + return nullptr; } f = &_win32_fhs[fd]; @@ -167,7 +167,7 @@ _fh_from_int( int fd, const char* func ) D( "_fh_from_int: invalid fd %d passed to %s", fd + WIN32_FH_BASE, func ); errno = EBADF; - return NULL; + return nullptr; } return f; @@ -186,12 +186,12 @@ _fh_to_int( FH f ) static FH _fh_alloc( FHClass clazz ) { - FH f = NULL; + FH f = nullptr; std::lock_guard lock(_win32_lock); for (int i = _win32_fh_next; i < WIN32_MAX_FHS; ++i) { - if (_win32_fhs[i].clazz == NULL) { + if (_win32_fhs[i].clazz == nullptr) { f = &_win32_fhs[i]; _win32_fh_next = i + 1; f->clazz = clazz; @@ -226,7 +226,7 @@ _fh_close( FH f ) f->name[0] = '\0'; f->eof = 0; f->used = 0; - f->clazz = NULL; + f->clazz = nullptr; } return 0; } @@ -269,7 +269,7 @@ static int _fh_file_close(FH f) { static int _fh_file_read(FH f, void* buf, int len) { DWORD read_bytes; - if (!ReadFile(f->fh_handle, buf, (DWORD)len, &read_bytes, NULL)) { + if (!ReadFile(f->fh_handle, buf, (DWORD)len, &read_bytes, nullptr)) { D("adb_read: could not read %d bytes from %s", len, f->name); errno = EIO; return -1; @@ -282,7 +282,7 @@ static int _fh_file_read(FH f, void* buf, int len) { static int _fh_file_write(FH f, const void* buf, int len) { DWORD wrote_bytes; - if (!WriteFile(f->fh_handle, buf, (DWORD)len, &wrote_bytes, NULL)) { + if (!WriteFile(f->fh_handle, buf, (DWORD)len, &wrote_bytes, nullptr)) { D("adb_file_write: could not write %d bytes from %s", len, f->name); errno = EIO; return -1; @@ -337,7 +337,7 @@ static int _fh_file_lseek(FH f, int pos, int origin) { return -1; } - result = SetFilePointer(f->fh_handle, pos, NULL, method); + result = SetFilePointer(f->fh_handle, pos, nullptr, method); if (result == INVALID_SET_FILE_POINTER) { errno = EIO; return -1; @@ -387,7 +387,7 @@ int adb_open(const char* path, int options) { return -1; } f->fh_handle = - CreateFileW(path_wide.c_str(), desiredAccess, shareMode, NULL, OPEN_EXISTING, 0, NULL); + CreateFileW(path_wide.c_str(), desiredAccess, shareMode, nullptr, OPEN_EXISTING, 0, nullptr); if (f->fh_handle == INVALID_HANDLE_VALUE) { const DWORD err = GetLastError(); @@ -430,7 +430,7 @@ int adb_creat(const char* path, int mode) { return -1; } f->fh_handle = CreateFileW(path_wide.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); if (f->fh_handle == INVALID_HANDLE_VALUE) { const DWORD err = GetLastError(); @@ -461,7 +461,7 @@ int adb_creat(const char* path, int mode) { int adb_read(int fd, void* buf, int len) { FH f = _fh_from_int(fd, __func__); - if (f == NULL) { + if (f == nullptr) { errno = EBADF; return -1; } @@ -472,7 +472,7 @@ int adb_read(int fd, void* buf, int len) { int adb_write(int fd, const void* buf, int len) { FH f = _fh_from_int(fd, __func__); - if (f == NULL) { + if (f == nullptr) { errno = EBADF; return -1; } @@ -483,7 +483,7 @@ int adb_write(int fd, const void* buf, int len) { ssize_t adb_writev(int fd, const adb_iovec* iov, int iovcnt) { FH f = _fh_from_int(fd, __func__); - if (f == NULL) { + if (f == nullptr) { errno = EBADF; return -1; } @@ -1700,7 +1700,7 @@ static int _console_read(const HANDLE console, void* buf, size_t len) { // The following emulation code should write the output sequence to // either seqstr or to seqbuf and seqbuflen. - const char* seqstr = NULL; // NULL terminated C-string + const char* seqstr = nullptr; // NULL terminated C-string // Enough space for max sequence string below, plus modifiers and/or // escape prefix. char seqbuf[16]; @@ -1998,7 +1998,7 @@ static int _console_read(const HANDLE console, void* buf, size_t len) { // * seqstr is set (and strlen can be used to determine the length). // * seqbuf and seqbuflen are set // Fallback to ch from Windows. - if (seqstr != NULL) { + if (seqstr != nullptr) { out = seqstr; outlen = strlen(seqstr); } else if (seqbuflen > 0) { @@ -2068,9 +2068,9 @@ void stdin_raw_init() { } void stdin_raw_restore() { - if (_console_handle != NULL) { + if (_console_handle != nullptr) { const HANDLE in = _console_handle; - _console_handle = NULL; // clear state + _console_handle = nullptr; // clear state if (!SetConsoleMode(in, _old_console_mode)) { // This really should not fail. @@ -2082,7 +2082,7 @@ void stdin_raw_restore() { // Called by 'adb shell' and 'adb exec-in' (via unix_read()) to read from stdin. int unix_read_interruptible(int fd, void* buf, size_t len) { - if ((fd == STDIN_FILENO) && (_console_handle != NULL)) { + if ((fd == STDIN_FILENO) && (_console_handle != nullptr)) { // If it is a request to read from stdin, and stdin_raw_init() has been // called, and it successfully configured the console, then read from // the console using Win32 console APIs and partially emulate a unix @@ -2442,7 +2442,7 @@ static int _console_write_utf8(const char* const buf, const size_t buf_size, FIL // Write UTF-16 to the console. DWORD written = 0; - if (!WriteConsoleW(console, utf16.c_str(), utf16.length(), &written, NULL)) { + if (!WriteConsoleW(console, utf16.c_str(), utf16.length(), &written, nullptr)) { errno = EIO; return -1; } @@ -2486,7 +2486,7 @@ int adb_vfprintf(FILE *stream, const char *format, va_list ap) { // If there is an associated Win32 console, write to it specially, // otherwise defer to the regular C Runtime, passing it UTF-8. - if (console != NULL) { + if (console != nullptr) { return _console_vfprintf(console, stream, format, ap); } else { // If vfprintf is a macro, undefine it, so we can call the real @@ -2577,7 +2577,7 @@ size_t adb_fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream) { // If there is an associated Win32 console, write to it specially, // otherwise defer to the regular C Runtime, passing it UTF-8. - if (console != NULL) { + if (console != nullptr) { return _console_fwrite(ptr, size, nmemb, stream, console); } else { // If fwrite is a macro, undefine it, so we can call the real diff --git a/adb/transport.cpp b/adb/transport.cpp index 7db9bf218..f2c40d2f3 100644 --- a/adb/transport.cpp +++ b/adb/transport.cpp @@ -404,7 +404,7 @@ void send_packet(apacket* p, atransport* t) { VLOG(TRANSPORT) << dump_packet(t->serial, "to remote", p); - if (t == NULL) { + if (t == nullptr) { fatal("Transport is null"); } @@ -467,7 +467,7 @@ static void device_tracker_close(asocket* socket) { D("device tracker %p removed", tracker); if (peer) { - peer->peer = NULL; + peer->peer = nullptr; peer->close(peer); } device_tracker_remove(tracker); @@ -699,7 +699,7 @@ void init_transport_registration(void) { transport_registration_recv = s[1]; transport_registration_fde = - fdevent_create(transport_registration_recv, transport_registration_func, 0); + fdevent_create(transport_registration_recv, transport_registration_func, nullptr); fdevent_set(transport_registration_fde, FDE_READ); } diff --git a/adb/transport_local.cpp b/adb/transport_local.cpp index 181d6665d..fa3823854 100644 --- a/adb/transport_local.cpp +++ b/adb/transport_local.cpp @@ -490,7 +490,7 @@ int init_socket_transport(atransport* t, int s, int adb_port, int local) { std::make_unique(std::move(emulator_connection))); std::lock_guard lock(local_transports_lock); atransport* existing_transport = find_emulator_transport_by_adb_port_locked(adb_port); - if (existing_transport != NULL) { + if (existing_transport != nullptr) { D("local transport for port %d already registered (%p)?", adb_port, existing_transport); fail = -1; } else if (local_transports.size() >= ADB_LOCAL_TRANSPORT_MAX) {