Replacing NULL with nullptr in core/
[ Merge of http://go/wvgerrit/84647 ] [ Merge of http://go/wvgerrit/84648 ] Replacing most instances of C's NULL with C++'s nullptr. Also changed how a NULL check is performed on smart pointers. They provided an implicit boolean operator for null checks, meaning the underlying pointer does not need to be compared directly (as it was in some places before). Note that clang-format has performed additional changes to some of the test files that have not yet been formatted. Bug: 120602075 Test: Linux and Android unittests Change-Id: I06ddebe34b0ea6dfecedb5527e7e808e32f5269a
This commit is contained in:
@@ -68,8 +68,8 @@ shared_mutex CryptoSession::static_field_mutex_;
|
||||
shared_mutex CryptoSession::oem_crypto_mutex_;
|
||||
bool CryptoSession::initialized_ = false;
|
||||
int CryptoSession::session_count_ = 0;
|
||||
UsageTableHeader* CryptoSession::usage_table_header_l1_ = NULL;
|
||||
UsageTableHeader* CryptoSession::usage_table_header_l3_ = NULL;
|
||||
UsageTableHeader* CryptoSession::usage_table_header_l1_ = nullptr;
|
||||
UsageTableHeader* CryptoSession::usage_table_header_l3_ = nullptr;
|
||||
std::atomic<uint64_t> CryptoSession::request_id_index_source_(0);
|
||||
|
||||
size_t GetOffset(std::string message, std::string field) {
|
||||
@@ -184,7 +184,7 @@ CryptoSession::CryptoSession(metrics::CryptoMetrics* metrics)
|
||||
requested_security_level_(kLevelDefault),
|
||||
is_usage_support_type_valid_(false),
|
||||
usage_support_type_(kUnknownUsageSupport),
|
||||
usage_table_header_(NULL),
|
||||
usage_table_header_(nullptr),
|
||||
cipher_mode_(kCipherModeCtr),
|
||||
api_version_(0) {
|
||||
assert(metrics);
|
||||
@@ -272,13 +272,13 @@ void CryptoSession::Terminate() {
|
||||
LOGE("OEMCrypto_Terminate failed: status = %d", static_cast<int>(sts));
|
||||
}
|
||||
|
||||
if (usage_table_header_l1_ != NULL) {
|
||||
if (usage_table_header_l1_ != nullptr) {
|
||||
delete usage_table_header_l1_;
|
||||
usage_table_header_l1_ = NULL;
|
||||
usage_table_header_l1_ = nullptr;
|
||||
}
|
||||
if (usage_table_header_l3_ != NULL) {
|
||||
if (usage_table_header_l3_ != nullptr) {
|
||||
delete usage_table_header_l3_;
|
||||
usage_table_header_l3_ = NULL;
|
||||
usage_table_header_l3_ = nullptr;
|
||||
}
|
||||
|
||||
initialized_ = false;
|
||||
@@ -472,7 +472,7 @@ CdmResponseType CryptoSession::GetExternalDeviceUniqueId(
|
||||
size_t id_length = 0;
|
||||
OEMCryptoResult sts;
|
||||
WithOecReadLock("GetExternalDeviceUniqueId", [&] {
|
||||
sts = OEMCrypto_GetDeviceID(NULL, &id_length, requested_security_level_);
|
||||
sts = OEMCrypto_GetDeviceID(nullptr, &id_length, requested_security_level_);
|
||||
});
|
||||
metrics_->oemcrypto_get_device_id_.Increment(sts);
|
||||
|
||||
@@ -710,7 +710,7 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
|
||||
UsageTableHeader** header = security_level == kSecurityLevelL1
|
||||
? &usage_table_header_l1_
|
||||
: &usage_table_header_l3_;
|
||||
if (*header == NULL) {
|
||||
if (*header == nullptr) {
|
||||
*header = new UsageTableHeader();
|
||||
// Ignore errors since we do not know when a session is opened,
|
||||
// if it is intended to be used for offline/usage session related
|
||||
@@ -721,8 +721,8 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
|
||||
auto_lock.lock();
|
||||
if (!is_usage_table_header_inited) {
|
||||
delete *header;
|
||||
*header = NULL;
|
||||
usage_table_header_ = NULL;
|
||||
*header = nullptr;
|
||||
usage_table_header_ = nullptr;
|
||||
return NO_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -1279,7 +1279,7 @@ CdmResponseType CryptoSession::GenerateUsageReport(
|
||||
OEMCryptoResult status;
|
||||
WithOecWriteLock("GenerateUsageReport Attempt 1", [&] {
|
||||
status = OEMCrypto_ReportUsage(oec_session_id_, pst,
|
||||
provider_session_token.length(), NULL,
|
||||
provider_session_token.length(), nullptr,
|
||||
&usage_length);
|
||||
});
|
||||
metrics_->oemcrypto_report_usage_.Increment(status);
|
||||
@@ -1514,9 +1514,9 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey(
|
||||
LOGV("Rewrapping device RSA key: id = %u", oec_session_id_);
|
||||
|
||||
const uint8_t* signed_msg = reinterpret_cast<const uint8_t*>(message.data());
|
||||
const uint8_t* msg_rsa_key = NULL;
|
||||
const uint8_t* msg_rsa_key_iv = NULL;
|
||||
const uint32_t* msg_nonce = NULL;
|
||||
const uint8_t* msg_rsa_key = nullptr;
|
||||
const uint8_t* msg_rsa_key_iv = nullptr;
|
||||
const uint32_t* msg_nonce = nullptr;
|
||||
if (enc_rsa_key.size() >= MAC_KEY_SIZE && rsa_key_iv.size() >= KEY_IV_SIZE) {
|
||||
msg_rsa_key = signed_msg + GetOffset(message, enc_rsa_key);
|
||||
msg_rsa_key_iv = signed_msg + GetOffset(message, rsa_key_iv);
|
||||
@@ -1524,7 +1524,7 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey(
|
||||
GetOffset(message, nonce));
|
||||
}
|
||||
|
||||
// Gets wrapped_rsa_key_length by passing NULL as uint8_t* wrapped_rsa_key
|
||||
// Gets wrapped_rsa_key_length by passing nullptr as uint8_t* wrapped_rsa_key
|
||||
// and 0 as wrapped_rsa_key_length.
|
||||
size_t wrapped_rsa_key_length = 0;
|
||||
OEMCryptoResult status;
|
||||
@@ -1533,7 +1533,7 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey(
|
||||
oec_session_id_, signed_msg, message.size(),
|
||||
reinterpret_cast<const uint8_t*>(signature.data()),
|
||||
signature.size(), msg_nonce, msg_rsa_key, enc_rsa_key.size(),
|
||||
msg_rsa_key_iv, NULL, &wrapped_rsa_key_length),
|
||||
msg_rsa_key_iv, nullptr, &wrapped_rsa_key_length),
|
||||
metrics_, oemcrypto_rewrap_device_rsa_key_, status);
|
||||
});
|
||||
|
||||
@@ -1567,10 +1567,10 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey30(
|
||||
LOGV("Rewrapping Device RSA key 30: id = %u", oec_session_id_);
|
||||
|
||||
const uint8_t* signed_msg = reinterpret_cast<const uint8_t*>(message.data());
|
||||
const uint8_t* msg_private_key = NULL;
|
||||
const uint8_t* msg_iv = NULL;
|
||||
const uint32_t* msg_nonce = NULL;
|
||||
const uint8_t* msg_wrapping_key = NULL;
|
||||
const uint8_t* msg_private_key = nullptr;
|
||||
const uint8_t* msg_iv = nullptr;
|
||||
const uint32_t* msg_nonce = nullptr;
|
||||
const uint8_t* msg_wrapping_key = nullptr;
|
||||
if (private_key.size() >= MAC_KEY_SIZE && iv.size() >= KEY_IV_SIZE) {
|
||||
msg_private_key = signed_msg + GetOffset(message, private_key);
|
||||
msg_iv = signed_msg + GetOffset(message, iv);
|
||||
@@ -1579,7 +1579,7 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey30(
|
||||
msg_wrapping_key = signed_msg + GetOffset(message, wrapping_key);
|
||||
}
|
||||
|
||||
// Gets wrapped_rsa_key_length by passing NULL as uint8_t* wrapped_rsa_key
|
||||
// Gets wrapped_rsa_key_length by passing nullptr as uint8_t* wrapped_rsa_key
|
||||
// and 0 as wrapped_rsa_key_length.
|
||||
size_t wrapped_private_key_length = 0;
|
||||
OEMCryptoResult status;
|
||||
@@ -1587,7 +1587,7 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey30(
|
||||
M_TIME(status = OEMCrypto_RewrapDeviceRSAKey30(
|
||||
oec_session_id_, msg_nonce, msg_wrapping_key,
|
||||
wrapping_key.size(), msg_private_key, private_key.size(), msg_iv,
|
||||
NULL, &wrapped_private_key_length),
|
||||
nullptr, &wrapped_private_key_length),
|
||||
metrics_, oemcrypto_rewrap_device_rsa_key_30_, status);
|
||||
});
|
||||
|
||||
@@ -2374,8 +2374,9 @@ CdmResponseType CryptoSession::UpdateUsageEntry(
|
||||
size_t usage_entry_len = 0;
|
||||
OEMCryptoResult result;
|
||||
WithOecWriteLock("UpdateUsageEntry Attempt 1", [&] {
|
||||
result = OEMCrypto_UpdateUsageEntry(
|
||||
oec_session_id_, NULL, &usage_table_header_len, NULL, &usage_entry_len);
|
||||
result = OEMCrypto_UpdateUsageEntry(oec_session_id_, nullptr,
|
||||
&usage_table_header_len, nullptr,
|
||||
&usage_entry_len);
|
||||
});
|
||||
metrics_->oemcrypto_update_usage_entry_.Increment(result);
|
||||
|
||||
@@ -2417,7 +2418,7 @@ CdmResponseType CryptoSession::ShrinkUsageTableHeader(
|
||||
OEMCryptoResult result;
|
||||
WithOecWriteLock("ShrinkUsageTableHeader Attempt 1", [&] {
|
||||
result = OEMCrypto_ShrinkUsageTableHeader(requested_security_level_,
|
||||
new_entry_count, NULL,
|
||||
new_entry_count, nullptr,
|
||||
&usage_table_header_len);
|
||||
metrics_->oemcrypto_shrink_usage_table_header_.Increment(result);
|
||||
});
|
||||
@@ -2726,7 +2727,7 @@ OEMCryptoResult CryptoSession::DecryptInChunks(
|
||||
const uint8_t* const buffer_end =
|
||||
params.encrypt_buffer + additional_offset + chunk_size;
|
||||
|
||||
const uint8_t* block_end = NULL;
|
||||
const uint8_t* block_end = nullptr;
|
||||
if (pattern_length_in_bytes == 0) {
|
||||
// For cbc1, the last encrypted block is the last block of the
|
||||
// subsample.
|
||||
@@ -2814,7 +2815,7 @@ CryptoSession* CryptoSession::MakeCryptoSession(
|
||||
metrics::CryptoMetrics* crypto_metrics) {
|
||||
std::unique_lock<std::mutex> auto_lock(factory_mutex_);
|
||||
// If the factory_ has not been set, then use a default factory.
|
||||
if (factory_.get() == NULL) factory_.reset(new CryptoSessionFactory());
|
||||
if (!factory_) factory_.reset(new CryptoSessionFactory());
|
||||
return factory_->MakeCryptoSession(crypto_metrics);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user