Skip to content

Commit

Permalink
Update from the upstream.
Browse files Browse the repository at this point in the history
* Code refactoring.
  • Loading branch information
hiroyuki-komatsu committed Nov 1, 2020
1 parent 08c8342 commit 4700ed5
Show file tree
Hide file tree
Showing 174 changed files with 1,087 additions and 960 deletions.
3 changes: 2 additions & 1 deletion src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ filegroup(
oss_android = ["//android/jni:mozc_lib"],
oss_linux = [
"//gui/tool:mozc_tool",
"//unix/emacs:mozc_emacs_helper",
"//unix/ibus:ibus_mozc",
"//renderer:mozc_renderer",
"//server:mozc_server",
"//unix/ibus:ibus_mozc",
],
),
)
4 changes: 2 additions & 2 deletions src/base/clock_mock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ bool ClockMock::GetTmWithOffsetSecond(time_t offset_sec, tm *output) {
}
#elif defined(OS_NACL)
const time_t localtime_sec = modified_sec + timezone_offset_sec_;
if (gmtime_r(&localtime_sec, output) == NULL) {
if (gmtime_r(&localtime_sec, output) == nullptr) {
return false;
}
#else // !OS_WIN && !OS_NACL
if (gmtime_r(&modified_sec, output) == NULL) {
if (gmtime_r(&modified_sec, output) == nullptr) {
return false;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/base/compiler_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
// "Compiler warning C4355: 'this': used in base member initializer list"
// http://msdn.microsoft.com/en-us/library/3c594ae3.aspx
// example:
// Foo::Foo() : x(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(y(this)) {}
// Foo::Foo() : x(nullptr), ALLOW_THIS_IN_INITIALIZER_LIST(y(this)) {}
#if defined(_MSC_VER)
#define ALLOW_THIS_IN_INITIALIZER_LIST(code) \
__pragma(warning(push)) __pragma(warning(disable : 4355)) \
Expand Down
12 changes: 6 additions & 6 deletions src/base/config_file_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ std::istream *ConfigFileStream::Open(const std::string &filename,
return ifs;
}
delete ifs;
return NULL;
return nullptr;
}
}
// user://foo.bar.txt
Expand All @@ -118,7 +118,7 @@ std::istream *ConfigFileStream::Open(const std::string &filename,
return ifs;
}
delete ifs;
return NULL;
return nullptr;
// file:///foo.map
} else if (Util::StartsWith(filename, kFilePrefix)) {
const std::string new_filename = RemovePrefix(kFilePrefix, filename);
Expand All @@ -128,7 +128,7 @@ std::istream *ConfigFileStream::Open(const std::string &filename,
return ifs;
}
delete ifs;
return NULL;
return nullptr;
} else if (Util::StartsWith(filename, kMemoryPrefix)) {
std::istringstream *ifs = new std::istringstream(
Singleton<OnMemoryFileMap>::get()->get(filename), mode);
Expand All @@ -137,7 +137,7 @@ std::istream *ConfigFileStream::Open(const std::string &filename,
return ifs;
}
delete ifs;
return NULL;
return nullptr;
} else {
LOG(WARNING) << filename << " has no prefix. open from localfile";
InputFileStream *ifs = new InputFileStream(filename.c_str(), mode);
Expand All @@ -146,10 +146,10 @@ std::istream *ConfigFileStream::Open(const std::string &filename,
return ifs;
}
delete ifs;
return NULL;
return nullptr;
}

return NULL;
return nullptr;
}

bool ConfigFileStream::AtomicUpdate(const std::string &filename,
Expand Down
2 changes: 1 addition & 1 deletion src/base/cpu_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ float CPUStats::GetCurrentProcessCPULoad() {
// OSX's basic_info_t has no filed |creation_time|, we cannot use it.
// The initial value might be different from the real CPU load.
struct timeval tv;
gettimeofday(&tv, NULL);
gettimeofday(&tv, nullptr);

const uint64 total_times = 1000000ULL * tv.tv_sec + tv.tv_usec;
const uint64 cpu_times = TimeValueTToInt64(task_times_info.user_time) +
Expand Down
34 changes: 17 additions & 17 deletions src/base/crash_report_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ int g_reference_count = 0;

// The CRITICAL_SECTION struct used for creating or deleting ExceptionHandler in
// a mutually exclusive manner.
CRITICAL_SECTION *g_critical_section = NULL;
CRITICAL_SECTION *g_critical_section = nullptr;

google_breakpad::ExceptionHandler *g_handler = NULL;
google_breakpad::ExceptionHandler *g_handler = nullptr;

// Returns the name of the build mode.
std::wstring GetBuildMode() {
Expand All @@ -94,10 +94,10 @@ std::wstring GetBuildMode() {
}

// Reduces the size of the string |str| to a max of 64 chars (Extra 1 char is
// trimmed for NULL-terminator so effective characters are 63 characters).
// trimmed for nullptr-terminator so effective characters are 63 characters).
// Required because breakpad's CustomInfoEntry raises an invalid_parameter error
// if the string we want to set is longer than 64 characters, including
// NULL-terminator.
// nullptr-terminator.
std::wstring TrimToBreakpadMax(const std::wstring &str) {
std::wstring shorter(str);
return shorter.substr(0,
Expand All @@ -120,7 +120,7 @@ google_breakpad::CustomClientInfo *GetCustomInfo() {
{
int num_args = 0;
wchar_t **args = ::CommandLineToArgvW(::GetCommandLineW(), &num_args);
if (args != NULL) {
if (args != nullptr) {
if (num_args > 1) {
switch1.set_value(TrimToBreakpadMax(args[1]).c_str());
}
Expand Down Expand Up @@ -153,12 +153,12 @@ class ScopedCriticalSection {
public:
explicit ScopedCriticalSection(CRITICAL_SECTION *critical_section)
: critical_section_(critical_section) {
if (critical_section_ != NULL) {
if (critical_section_ != nullptr) {
EnterCriticalSection(critical_section_);
}
}
~ScopedCriticalSection() {
if (critical_section_ != NULL) {
if (critical_section_ != nullptr) {
LeaveCriticalSection(critical_section_);
}
}
Expand All @@ -169,11 +169,11 @@ class ScopedCriticalSection {

// get the handle to the module containing the given executing address
HMODULE GetModuleHandleFromAddress(void *address) {
// address may be NULL
// address may be nullptr
MEMORY_BASIC_INFORMATION mbi;
SIZE_T result = VirtualQuery(address, &mbi, sizeof(mbi));
if (0 == result) {
return NULL;
return nullptr;
}
return static_cast<HMODULE>(mbi.AllocationBase);
}
Expand All @@ -185,7 +185,7 @@ HMODULE GetCurrentModuleHandle() {

// Check to see if an address is in the current module.
bool IsAddressInCurrentModule(void *address) {
// address may be NULL
// address may be nullptr
return GetCurrentModuleHandle() == GetModuleHandleFromAddress(address);
}

Expand Down Expand Up @@ -226,7 +226,7 @@ bool IsCurrentModuleInStack(PCONTEXT context) {

bool FilterHandler(void *context, EXCEPTION_POINTERS *exinfo,
MDRawAssertionInfo *assertion) {
if (exinfo == NULL) {
if (exinfo == nullptr) {
// We do not catch CRT error in release build.
#ifdef MOZC_NO_LOGGING
return false;
Expand Down Expand Up @@ -255,7 +255,7 @@ bool CrashReportHandler::Initialize(bool check_address) {
ScopedCriticalSection critical_section(g_critical_section);
DCHECK_GE(g_reference_count, 0);
++g_reference_count;
if (g_reference_count == 1 && g_handler == NULL) {
if (g_reference_count == 1 && g_handler == nullptr) {
const string acrashdump_directory = SystemUtil::GetCrashReportDirectory();
// create a crash dump directory if not exist.
if (!FileUtil::FileExists(acrashdump_directory)) {
Expand All @@ -266,13 +266,13 @@ bool CrashReportHandler::Initialize(bool check_address) {
Util::UTF8ToWide(acrashdump_directory, &crashdump_directory);

google_breakpad::ExceptionHandler::FilterCallback filter_callback =
check_address ? FilterHandler : NULL;
check_address ? FilterHandler : nullptr;
const auto kCrashDumpType = static_cast<MINIDUMP_TYPE>(
MiniDumpWithUnloadedModules | MiniDumpWithProcessThreadData);
g_handler = new google_breakpad::ExceptionHandler(
crashdump_directory.c_str(), filter_callback,
NULL, // MinidumpCallback
NULL, // callback_context
nullptr, // MinidumpCallback
nullptr, // callback_context
google_breakpad::ExceptionHandler::HANDLER_ALL, kCrashDumpType,
GetCrashHandlerPipeName().c_str(), GetCustomInfo());

Expand All @@ -293,9 +293,9 @@ bool CrashReportHandler::Uninitialize() {
ScopedCriticalSection critical_section(g_critical_section);
--g_reference_count;
DCHECK_GE(g_reference_count, 0);
if (g_reference_count == 0 && g_handler != NULL) {
if (g_reference_count == 0 && g_handler != nullptr) {
delete g_handler;
g_handler = NULL;
g_handler = nullptr;
return true;
}
return false;
Expand Down
21 changes: 11 additions & 10 deletions src/base/encryptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ bool Encryptor::Key::DeriveFromPassword(const std::string &password,
return false;
}

if (iv != NULL) {
if (iv != nullptr) {
memcpy(data_->iv, iv, iv_size());
} else {
memset(data_->iv, '\0', iv_size());
Expand All @@ -185,8 +185,8 @@ Encryptor::Key::Key() : data_(new Encryptor::Key::InternalData) {}
Encryptor::Key::~Key() {}

bool Encryptor::EncryptString(const Encryptor::Key &key, std::string *data) {
if (data == NULL || data->empty()) {
LOG(ERROR) << "data is NULL or empty";
if (data == nullptr || data->empty()) {
LOG(ERROR) << "data is nullptr or empty";
return false;
}
size_t size = data->size();
Expand All @@ -201,8 +201,8 @@ bool Encryptor::EncryptString(const Encryptor::Key &key, std::string *data) {
}

bool Encryptor::DecryptString(const Encryptor::Key &key, std::string *data) {
if (data == NULL || data->empty()) {
LOG(ERROR) << "data is NULL or empty";
if (data == nullptr || data->empty()) {
LOG(ERROR) << "data is nullptr or empty";
return false;
}
size_t size = data->size();
Expand All @@ -223,7 +223,7 @@ bool Encryptor::EncryptArray(const Encryptor::Key &key, char *buf,
return false;
}

if (buf == NULL || buf_size == NULL || *buf_size == 0) {
if (buf == nullptr || buf_size == nullptr || *buf_size == 0) {
LOG(ERROR) << "invalid buffer given";
return false;
}
Expand Down Expand Up @@ -252,7 +252,7 @@ bool Encryptor::DecryptArray(const Encryptor::Key &key, char *buf,
return false;
}

if (buf == NULL || buf_size == NULL || *buf_size == 0) {
if (buf == nullptr || buf_size == nullptr || *buf_size == 0) {
LOG(ERROR) << "invalid buffer given";
return false;
}
Expand Down Expand Up @@ -304,7 +304,7 @@ bool Encryptor::ProtectData(const string &plain_text, string *cipher_text) {
input.cbData = static_cast<DWORD>(plain_text.size());

DATA_BLOB output;
const BOOL result = ::CryptProtectData(&input, L"", NULL, NULL, NULL,
const BOOL result = ::CryptProtectData(&input, L"", nullptr, nullptr, nullptr,
CRYPTPROTECT_UI_FORBIDDEN, &output);
if (!result) {
LOG(ERROR) << "CryptProtectData failed: " << ::GetLastError();
Expand All @@ -327,8 +327,9 @@ bool Encryptor::UnprotectData(const string &cipher_text, string *plain_text) {
input.cbData = static_cast<DWORD>(cipher_text.length());

DATA_BLOB output;
const BOOL result = ::CryptUnprotectData(&input, NULL, NULL, NULL, NULL,
CRYPTPROTECT_UI_FORBIDDEN, &output);
const BOOL result =
::CryptUnprotectData(&input, nullptr, nullptr, nullptr, nullptr,
CRYPTPROTECT_UI_FORBIDDEN, &output);
if (!result) {
LOG(ERROR) << "CryptUnprotectData failed: " << ::GetLastError();
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/base/encryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ class Encryptor {
// Make a session key from password and salt.
// You can also set an initialization vector whose
// size must be iv_size().
// if iv is NULL, default iv is used.
// if iv is nullptr, default iv is used.
bool DeriveFromPassword(const std::string &password,
const std::string &salt, const uint8 *iv);

// use default iv.
bool DeriveFromPassword(const std::string &password,
const std::string &salt) {
return DeriveFromPassword(password, salt, NULL);
return DeriveFromPassword(password, salt, nullptr);
}

// use empty salt and default iv
bool DeriveFromPassword(const std::string &password) {
return DeriveFromPassword(password, "", NULL);
return DeriveFromPassword(password, "", nullptr);
}

// return block size. the result should be 16byte with AES
Expand Down
2 changes: 1 addition & 1 deletion src/base/encryptor_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int main(int argc, char **argv) {
}

const uint8 *iv = FLAGS_iv.empty()
? NULL
? nullptr
: reinterpret_cast<const uint8 *>(FLAGS_iv.data());

if (!FLAGS_input_file.empty() && !FLAGS_output_file.empty()) {
Expand Down
4 changes: 2 additions & 2 deletions src/base/encryptor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ TEST(EncryptorTest, EncryptBatch) {
EXPECT_NE(original, encrypted4);

// invalid values
EXPECT_FALSE(Encryptor::EncryptString(key1, NULL));
EXPECT_FALSE(Encryptor::DecryptString(key1, NULL));
EXPECT_FALSE(Encryptor::EncryptString(key1, nullptr));
EXPECT_FALSE(Encryptor::DecryptString(key1, nullptr));

// empty string
std::string empty_string;
Expand Down
2 changes: 1 addition & 1 deletion src/base/multifile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ InputMultiFile::InputMultiFile(const std::string &filenames,
InputMultiFile::~InputMultiFile() { ifs_.reset(); }

bool InputMultiFile::ReadLine(std::string *line) {
if (ifs_.get() == NULL) {
if (ifs_.get() == nullptr) {
return false;
}
do {
Expand Down
4 changes: 2 additions & 2 deletions src/base/mutex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pthread_rwlock_t *AsPthreadRWLockT(T *opaque_buffer) {
} // namespace

ReaderWriterMutex::ReaderWriterMutex() {
pthread_rwlock_init(AsPthreadRWLockT(&opaque_buffer_), NULL);
pthread_rwlock_init(AsPthreadRWLockT(&opaque_buffer_), nullptr);
}

ReaderWriterMutex::~ReaderWriterMutex() {
Expand Down Expand Up @@ -213,7 +213,7 @@ bool ReaderWriterMutex::MultipleReadersThreadsSupported() { return true; }
// Fallback implementations as ReaderWriterLock is not available.
ReaderWriterMutex::ReaderWriterMutex() {
// Non-recursive lock is OK.
pthread_mutex_init(AsPthreadMutexT(&opaque_buffer_), NULL);
pthread_mutex_init(AsPthreadMutexT(&opaque_buffer_), nullptr);
}

ReaderWriterMutex::~ReaderWriterMutex() {
Expand Down
10 changes: 5 additions & 5 deletions src/base/password_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ bool PlainPasswordManager::SetPassword(const std::string &password) const {
}

bool PlainPasswordManager::GetPassword(std::string *password) const {
if (password == NULL) {
LOG(ERROR) << "password is NULL";
if (password == nullptr) {
LOG(ERROR) << "password is nullptr";
return false;
}

Expand Down Expand Up @@ -231,8 +231,8 @@ bool WinMacPasswordManager::SetPassword(const string &password) const {
}

bool WinMacPasswordManager::GetPassword(string *password) const {
if (password == NULL) {
LOG(ERROR) << "password is NULL";
if (password == nullptr) {
LOG(ERROR) << "password is nullptr";
return false;
}

Expand Down Expand Up @@ -279,7 +279,7 @@ class PasswordManagerImpl {
public:
PasswordManagerImpl() {
password_manager_ = Singleton<DefaultPasswordManager>::get();
DCHECK(password_manager_ != NULL);
DCHECK(password_manager_ != nullptr);
}

bool InitPassword() {
Expand Down
Loading

0 comments on commit 4700ed5

Please sign in to comment.