Convert NULL/0 to nullptr or shorten to bool-like expression
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. !! is used in situations where the pointer is assigned to or returned as bool, otherwise CheckedPtr's more costly implicit T* cast operator would kick in. !! isn't needed in boolean expressions. Examples here: https://chromium-review.googlesource.com/c/chromium/src/+/2226003 Bug: 1080832 Change-Id: I8ebc83be2e96bf1598dd25ef5ca07c98134ccffd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2226318 Commit-Queue: Bartek Nowierski <bartekn@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Auto-Submit: Bartek Nowierski <bartekn@chromium.org> Cr-Commit-Position: refs/heads/master@{#774192}
This commit is contained in:

committed by
Commit Bot

parent
6da798c9a1
commit
c6a0a15ac1
chrome
browser
utility
importer
components
extensions/browser/api
socket
sockets_tcp
sockets_tcp_server
sockets_udp
ui/events/gesture_detection
@ -314,7 +314,7 @@ base::RunLoop* g_run_loop = nullptr;
|
||||
void HandleTestParameters(const base::CommandLine& command_line) {
|
||||
// This parameter causes a null pointer crash (crash reporter trigger).
|
||||
if (command_line.HasSwitch(switches::kBrowserCrashTest)) {
|
||||
int* bad_pointer = NULL;
|
||||
int* bad_pointer = nullptr;
|
||||
*bad_pointer = 0;
|
||||
}
|
||||
}
|
||||
@ -945,7 +945,7 @@ int ChromeBrowserMainParts::PreCreateThreadsImpl() {
|
||||
// properly. See issue 37766.
|
||||
// (Note that the callback mask here is empty. I don't want to register for
|
||||
// any callbacks, I just want to initialize the mechanism.)
|
||||
SecKeychainAddCallback(&KeychainCallback, 0, NULL);
|
||||
SecKeychainAddCallback(&KeychainCallback, 0, nullptr);
|
||||
#endif // defined(OS_MACOSX)
|
||||
|
||||
#if defined(OS_WIN) || defined(OS_MACOSX) || \
|
||||
@ -1706,7 +1706,7 @@ void ChromeBrowserMainParts::PostMainMessageLoopRun() {
|
||||
// Some tests don't set parameters.ui_task, so they started translate
|
||||
// language fetch that was never completed so we need to cleanup here
|
||||
// otherwise it will be done by the destructor in a wrong thread.
|
||||
TranslateService::Shutdown(parameters().ui_task == NULL);
|
||||
TranslateService::Shutdown(!parameters().ui_task);
|
||||
|
||||
if (notify_result_ == ProcessSingleton::PROCESS_NONE)
|
||||
process_singleton_->Cleanup();
|
||||
|
@ -128,7 +128,7 @@ template <>
|
||||
struct TypeConverter<mojom::AutocompleteMatchPtr, AutocompleteMatch> {
|
||||
static mojom::AutocompleteMatchPtr Convert(const AutocompleteMatch& input) {
|
||||
mojom::AutocompleteMatchPtr result(mojom::AutocompleteMatch::New());
|
||||
if (input.provider != NULL) {
|
||||
if (input.provider) {
|
||||
result->provider_name = std::string(input.provider->GetName());
|
||||
result->provider_done = input.provider->done();
|
||||
}
|
||||
@ -162,7 +162,7 @@ struct TypeConverter<mojom::AutocompleteMatchPtr, AutocompleteMatch> {
|
||||
result->type = AutocompleteMatchType::ToString(input.type);
|
||||
result->is_search_type = AutocompleteMatch::IsSearchType(input.type);
|
||||
result->has_tab_match = input.has_tab_match;
|
||||
if (input.associated_keyword.get() != NULL) {
|
||||
if (input.associated_keyword.get()) {
|
||||
result->associated_keyword =
|
||||
base::UTF16ToUTF8(input.associated_keyword->keyword);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ void PredictorsHandler::RegisterMessages() {
|
||||
|
||||
void PredictorsHandler::RequestAutocompleteActionPredictorDb(
|
||||
const base::ListValue* args) {
|
||||
const bool enabled = (autocomplete_action_predictor_ != NULL);
|
||||
const bool enabled = !!autocomplete_action_predictor_;
|
||||
base::DictionaryValue dict;
|
||||
dict.SetBoolean("enabled", enabled);
|
||||
if (enabled) {
|
||||
|
@ -35,7 +35,7 @@ bool NSSDecryptor::Init(const base::FilePath& dll_path,
|
||||
"flags=readOnly",
|
||||
db_path.value().c_str());
|
||||
db_slot_ = SECMOD_OpenUserDB(modspec.c_str());
|
||||
return db_slot_ != NULL;
|
||||
return !!db_slot_;
|
||||
}
|
||||
|
||||
// This method is based on some NSS code in
|
||||
|
@ -110,7 +110,7 @@ class POLICY_EXPORT Schema {
|
||||
|
||||
// Returns true if this Schema is valid. Schemas returned by the methods below
|
||||
// may be invalid, and in those cases the other methods must not be used.
|
||||
bool valid() const { return node_ != NULL; }
|
||||
bool valid() const { return !!node_; }
|
||||
|
||||
base::Value::Type type() const;
|
||||
|
||||
|
@ -61,7 +61,7 @@ class Entry {
|
||||
// the GetTypeRoot variant instead.
|
||||
Entry(BaseTransaction* trans, GetByServerTag, const std::string& tag);
|
||||
|
||||
bool good() const { return 0 != kernel_; }
|
||||
bool good() const { return !!kernel_; }
|
||||
|
||||
BaseTransaction* trans() const { return basetrans_; }
|
||||
|
||||
|
@ -72,7 +72,7 @@ class SocketResourceManagerInterface {
|
||||
template <typename T>
|
||||
class SocketResourceManager : public SocketResourceManagerInterface {
|
||||
public:
|
||||
SocketResourceManager() : manager_(NULL) {}
|
||||
SocketResourceManager() : manager_(nullptr) {}
|
||||
|
||||
bool SetBrowserContext(content::BrowserContext* context) override {
|
||||
manager_ = ApiResourceManager<T>::Get(context);
|
||||
@ -81,7 +81,7 @@ class SocketResourceManager : public SocketResourceManagerInterface {
|
||||
"If this assertion is failing during a test, then it is likely that "
|
||||
"TestExtensionSystem is failing to provide an instance of "
|
||||
"ApiResourceManager<Socket>.";
|
||||
return manager_ != NULL;
|
||||
return !!manager_;
|
||||
}
|
||||
|
||||
int Add(Socket* socket) override {
|
||||
|
@ -163,7 +163,7 @@ void SocketsTcpUpdateFunction::Work() {
|
||||
}
|
||||
|
||||
SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction()
|
||||
: socket_event_dispatcher_(NULL) {}
|
||||
: socket_event_dispatcher_(nullptr) {}
|
||||
|
||||
SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {}
|
||||
|
||||
@ -177,7 +177,7 @@ bool SocketsTcpSetPausedFunction::Prepare() {
|
||||
"If this assertion is failing during a test, then it is likely that "
|
||||
"TestExtensionSystem is failing to provide an instance of "
|
||||
"TCPSocketEventDispatcher.";
|
||||
return socket_event_dispatcher_ != NULL;
|
||||
return !!socket_event_dispatcher_;
|
||||
}
|
||||
|
||||
void SocketsTcpSetPausedFunction::Work() {
|
||||
@ -264,7 +264,7 @@ void SocketsTcpSetNoDelayFunction::OnCompleted(bool success) {
|
||||
}
|
||||
|
||||
SocketsTcpConnectFunction::SocketsTcpConnectFunction()
|
||||
: socket_event_dispatcher_(NULL) {}
|
||||
: socket_event_dispatcher_(nullptr) {}
|
||||
|
||||
SocketsTcpConnectFunction::~SocketsTcpConnectFunction() {}
|
||||
|
||||
@ -278,7 +278,7 @@ bool SocketsTcpConnectFunction::Prepare() {
|
||||
"If this assertion is failing during a test, then it is likely that "
|
||||
"TestExtensionSystem is failing to provide an instance of "
|
||||
"TCPSocketEventDispatcher.";
|
||||
return socket_event_dispatcher_ != NULL;
|
||||
return !!socket_event_dispatcher_;
|
||||
}
|
||||
|
||||
void SocketsTcpConnectFunction::AsyncWorkStart() {
|
||||
@ -457,7 +457,7 @@ bool SocketsTcpGetSocketsFunction::Prepare() { return true; }
|
||||
void SocketsTcpGetSocketsFunction::Work() {
|
||||
std::vector<sockets_tcp::SocketInfo> socket_infos;
|
||||
std::unordered_set<int>* resource_ids = GetSocketIds();
|
||||
if (resource_ids != NULL) {
|
||||
if (resource_ids) {
|
||||
for (int socket_id : *resource_ids) {
|
||||
ResumableTCPSocket* socket = GetTcpSocket(socket_id);
|
||||
if (socket) {
|
||||
|
@ -123,7 +123,7 @@ void SocketsTcpServerUpdateFunction::Work() {
|
||||
}
|
||||
|
||||
SocketsTcpServerSetPausedFunction::SocketsTcpServerSetPausedFunction()
|
||||
: socket_event_dispatcher_(NULL) {}
|
||||
: socket_event_dispatcher_(nullptr) {}
|
||||
|
||||
SocketsTcpServerSetPausedFunction::~SocketsTcpServerSetPausedFunction() {}
|
||||
|
||||
@ -138,7 +138,7 @@ bool SocketsTcpServerSetPausedFunction::Prepare() {
|
||||
"If this assertion is failing during a test, then it is likely that "
|
||||
"TestExtensionSystem is failing to provide an instance of "
|
||||
"TCPServerSocketEventDispatcher.";
|
||||
return socket_event_dispatcher_ != NULL;
|
||||
return !!socket_event_dispatcher_;
|
||||
}
|
||||
|
||||
void SocketsTcpServerSetPausedFunction::Work() {
|
||||
@ -160,7 +160,7 @@ void SocketsTcpServerSetPausedFunction::Work() {
|
||||
}
|
||||
|
||||
SocketsTcpServerListenFunction::SocketsTcpServerListenFunction()
|
||||
: socket_event_dispatcher_(NULL) {}
|
||||
: socket_event_dispatcher_(nullptr) {}
|
||||
|
||||
SocketsTcpServerListenFunction::~SocketsTcpServerListenFunction() {}
|
||||
|
||||
@ -175,7 +175,7 @@ bool SocketsTcpServerListenFunction::Prepare() {
|
||||
"If this assertion is failing during a test, then it is likely that "
|
||||
"TestExtensionSystem is failing to provide an instance of "
|
||||
"TCPServerSocketEventDispatcher.";
|
||||
return socket_event_dispatcher_ != NULL;
|
||||
return !!socket_event_dispatcher_;
|
||||
}
|
||||
|
||||
void SocketsTcpServerListenFunction::AsyncWorkStart() {
|
||||
@ -297,7 +297,7 @@ bool SocketsTcpServerGetSocketsFunction::Prepare() { return true; }
|
||||
void SocketsTcpServerGetSocketsFunction::Work() {
|
||||
std::vector<sockets_tcp_server::SocketInfo> socket_infos;
|
||||
std::unordered_set<int>* resource_ids = GetSocketIds();
|
||||
if (resource_ids != NULL) {
|
||||
if (resource_ids) {
|
||||
for (int socket_id : *resource_ids) {
|
||||
ResumableTCPServerSocket* socket = GetTcpSocket(socket_id);
|
||||
if (socket) {
|
||||
|
@ -142,7 +142,7 @@ void SocketsUdpUpdateFunction::Work() {
|
||||
}
|
||||
|
||||
SocketsUdpSetPausedFunction::SocketsUdpSetPausedFunction()
|
||||
: socket_event_dispatcher_(NULL) {}
|
||||
: socket_event_dispatcher_(nullptr) {}
|
||||
|
||||
SocketsUdpSetPausedFunction::~SocketsUdpSetPausedFunction() {}
|
||||
|
||||
@ -156,7 +156,7 @@ bool SocketsUdpSetPausedFunction::Prepare() {
|
||||
"If this assertion is failing during a test, then it is likely that "
|
||||
"TestExtensionSystem is failing to provide an instance of "
|
||||
"UDPSocketEventDispatcher.";
|
||||
return socket_event_dispatcher_ != NULL;
|
||||
return !!socket_event_dispatcher_;
|
||||
}
|
||||
|
||||
void SocketsUdpSetPausedFunction::Work() {
|
||||
@ -178,7 +178,7 @@ void SocketsUdpSetPausedFunction::Work() {
|
||||
}
|
||||
|
||||
SocketsUdpBindFunction::SocketsUdpBindFunction()
|
||||
: socket_event_dispatcher_(NULL) {}
|
||||
: socket_event_dispatcher_(nullptr) {}
|
||||
|
||||
SocketsUdpBindFunction::~SocketsUdpBindFunction() {}
|
||||
|
||||
@ -192,7 +192,7 @@ bool SocketsUdpBindFunction::Prepare() {
|
||||
"If this assertion is failing during a test, then it is likely that "
|
||||
"TestExtensionSystem is failing to provide an instance of "
|
||||
"UDPSocketEventDispatcher.";
|
||||
return socket_event_dispatcher_ != NULL;
|
||||
return !!socket_event_dispatcher_;
|
||||
}
|
||||
|
||||
void SocketsUdpBindFunction::AsyncWorkStart() {
|
||||
@ -363,7 +363,7 @@ bool SocketsUdpGetSocketsFunction::Prepare() { return true; }
|
||||
void SocketsUdpGetSocketsFunction::Work() {
|
||||
std::vector<sockets_udp::SocketInfo> socket_infos;
|
||||
std::unordered_set<int>* resource_ids = GetSocketIds();
|
||||
if (resource_ids != NULL) {
|
||||
if (resource_ids) {
|
||||
for (int socket_id : *resource_ids) {
|
||||
ResumableUDPSocket* socket = GetUdpSocket(socket_id);
|
||||
if (socket) {
|
||||
|
@ -400,7 +400,7 @@ bool GestureDetector::OnTouchEvent(const MotionEvent& ev,
|
||||
handled = listener_->OnSingleTapUp(
|
||||
ev, 1 + current_single_tap_repeat_count_);
|
||||
if (defer_confirm_single_tap_ && should_process_double_tap &&
|
||||
double_tap_listener_ != NULL) {
|
||||
double_tap_listener_) {
|
||||
double_tap_listener_->OnSingleTapConfirmed(ev);
|
||||
}
|
||||
} else if (!all_pointers_within_slop_regions_) {
|
||||
|
Reference in New Issue
Block a user