Commit 18098171 by Eric Fiselier

replace instances of NULL with nullptr

parent 64ba2729
...@@ -65,7 +65,7 @@ PlatformColorCode GetPlatformColorCode(LogColor color) { ...@@ -65,7 +65,7 @@ PlatformColorCode GetPlatformColorCode(LogColor color) {
case COLOR_WHITE: case COLOR_WHITE:
return "7"; return "7";
default: default:
return NULL; return nullptr;
}; };
#endif #endif
} }
......
...@@ -24,7 +24,7 @@ namespace benchmark { ...@@ -24,7 +24,7 @@ namespace benchmark {
// unchanged and returns false. // unchanged and returns false.
bool ParseInt32(const std::string& src_text, const char* str, int32_t* value) { bool ParseInt32(const std::string& src_text, const char* str, int32_t* value) {
// Parses the environment variable as a decimal integer. // Parses the environment variable as a decimal integer.
char* end = NULL; char* end = nullptr;
const long long_value = strtol(str, &end, 10); // NOLINT const long long_value = strtol(str, &end, 10); // NOLINT
// Has strtol() consumed all characters in the string? // Has strtol() consumed all characters in the string?
...@@ -58,7 +58,7 @@ bool ParseInt32(const std::string& src_text, const char* str, int32_t* value) { ...@@ -58,7 +58,7 @@ bool ParseInt32(const std::string& src_text, const char* str, int32_t* value) {
// returns true; otherwise leaves *value unchanged and returns false. // returns true; otherwise leaves *value unchanged and returns false.
bool ParseDouble(const std::string& src_text, const char* str, double* value) { bool ParseDouble(const std::string& src_text, const char* str, double* value) {
// Parses the environment variable as a decimal integer. // Parses the environment variable as a decimal integer.
char* end = NULL; char* end = nullptr;
const double double_value = strtod(str, &end); // NOLINT const double double_value = strtod(str, &end); // NOLINT
// Has strtol() consumed all characters in the string? // Has strtol() consumed all characters in the string?
...@@ -76,9 +76,9 @@ bool ParseDouble(const std::string& src_text, const char* str, double* value) { ...@@ -76,9 +76,9 @@ bool ParseDouble(const std::string& src_text, const char* str, double* value) {
inline const char* GetEnv(const char* name) { inline const char* GetEnv(const char* name) {
#if defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) #if defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
// Environment variables which we programmatically clear will be set to the // Environment variables which we programmatically clear will be set to the
// empty string rather than unset (NULL). Handle that case. // empty string rather than unset (nullptr). Handle that case.
const char* const env = getenv(name); const char* const env = getenv(name);
return (env != NULL && env[0] != '\0') ? env : NULL; return (env != nullptr && env[0] != '\0') ? env : nullptr;
#else #else
return getenv(name); return getenv(name);
#endif #endif
...@@ -104,7 +104,7 @@ static std::string FlagToEnvVar(const char* flag) { ...@@ -104,7 +104,7 @@ static std::string FlagToEnvVar(const char* flag) {
bool BoolFromEnv(const char* flag, bool default_value) { bool BoolFromEnv(const char* flag, bool default_value) {
const std::string env_var = FlagToEnvVar(flag); const std::string env_var = FlagToEnvVar(flag);
const char* const string_value = GetEnv(env_var.c_str()); const char* const string_value = GetEnv(env_var.c_str());
return string_value == NULL ? default_value : strcmp(string_value, "0") != 0; return string_value == nullptr ? default_value : strcmp(string_value, "0") != 0;
} }
// Reads and returns a 32-bit integer stored in the environment // Reads and returns a 32-bit integer stored in the environment
...@@ -113,7 +113,7 @@ bool BoolFromEnv(const char* flag, bool default_value) { ...@@ -113,7 +113,7 @@ bool BoolFromEnv(const char* flag, bool default_value) {
int32_t Int32FromEnv(const char* flag, int32_t default_value) { int32_t Int32FromEnv(const char* flag, int32_t default_value) {
const std::string env_var = FlagToEnvVar(flag); const std::string env_var = FlagToEnvVar(flag);
const char* const string_value = GetEnv(env_var.c_str()); const char* const string_value = GetEnv(env_var.c_str());
if (string_value == NULL) { if (string_value == nullptr) {
// The environment variable is not set. // The environment variable is not set.
return default_value; return default_value;
} }
...@@ -133,23 +133,23 @@ int32_t Int32FromEnv(const char* flag, int32_t default_value) { ...@@ -133,23 +133,23 @@ int32_t Int32FromEnv(const char* flag, int32_t default_value) {
const char* StringFromEnv(const char* flag, const char* default_value) { const char* StringFromEnv(const char* flag, const char* default_value) {
const std::string env_var = FlagToEnvVar(flag); const std::string env_var = FlagToEnvVar(flag);
const char* const value = GetEnv(env_var.c_str()); const char* const value = GetEnv(env_var.c_str());
return value == NULL ? default_value : value; return value == nullptr ? default_value : value;
} }
// Parses a string as a command line flag. The string should have // Parses a string as a command line flag. The string should have
// the format "--flag=value". When def_optional is true, the "=value" // the format "--flag=value". When def_optional is true, the "=value"
// part can be omitted. // part can be omitted.
// //
// Returns the value of the flag, or NULL if the parsing failed. // Returns the value of the flag, or nullptr if the parsing failed.
const char* ParseFlagValue(const char* str, const char* flag, const char* ParseFlagValue(const char* str, const char* flag,
bool def_optional) { bool def_optional) {
// str and flag must not be NULL. // str and flag must not be nullptr.
if (str == NULL || flag == NULL) return NULL; if (str == nullptr || flag == nullptr) return nullptr;
// The flag must start with "--". // The flag must start with "--".
const std::string flag_str = std::string("--") + std::string(flag); const std::string flag_str = std::string("--") + std::string(flag);
const size_t flag_len = flag_str.length(); const size_t flag_len = flag_str.length();
if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL; if (strncmp(str, flag_str.c_str(), flag_len) != 0) return nullptr;
// Skips the flag name. // Skips the flag name.
const char* flag_end = str + flag_len; const char* flag_end = str + flag_len;
...@@ -160,7 +160,7 @@ const char* ParseFlagValue(const char* str, const char* flag, ...@@ -160,7 +160,7 @@ const char* ParseFlagValue(const char* str, const char* flag,
// If def_optional is true and there are more characters after the // If def_optional is true and there are more characters after the
// flag name, or if def_optional is false, there must be a '=' after // flag name, or if def_optional is false, there must be a '=' after
// the flag name. // the flag name.
if (flag_end[0] != '=') return NULL; if (flag_end[0] != '=') return nullptr;
// Returns the string after "=". // Returns the string after "=".
return flag_end + 1; return flag_end + 1;
...@@ -171,7 +171,7 @@ bool ParseBoolFlag(const char* str, const char* flag, bool* value) { ...@@ -171,7 +171,7 @@ bool ParseBoolFlag(const char* str, const char* flag, bool* value) {
const char* const value_str = ParseFlagValue(str, flag, true); const char* const value_str = ParseFlagValue(str, flag, true);
// Aborts if the parsing failed. // Aborts if the parsing failed.
if (value_str == NULL) return false; if (value_str == nullptr) return false;
// Converts the string value to a bool. // Converts the string value to a bool.
*value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F'); *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F');
...@@ -183,7 +183,7 @@ bool ParseInt32Flag(const char* str, const char* flag, int32_t* value) { ...@@ -183,7 +183,7 @@ bool ParseInt32Flag(const char* str, const char* flag, int32_t* value) {
const char* const value_str = ParseFlagValue(str, flag, false); const char* const value_str = ParseFlagValue(str, flag, false);
// Aborts if the parsing failed. // Aborts if the parsing failed.
if (value_str == NULL) return false; if (value_str == nullptr) return false;
// Sets *value to the value of the flag. // Sets *value to the value of the flag.
return ParseInt32(std::string("The value of flag --") + flag, value_str, return ParseInt32(std::string("The value of flag --") + flag, value_str,
...@@ -195,7 +195,7 @@ bool ParseDoubleFlag(const char* str, const char* flag, double* value) { ...@@ -195,7 +195,7 @@ bool ParseDoubleFlag(const char* str, const char* flag, double* value) {
const char* const value_str = ParseFlagValue(str, flag, false); const char* const value_str = ParseFlagValue(str, flag, false);
// Aborts if the parsing failed. // Aborts if the parsing failed.
if (value_str == NULL) return false; if (value_str == nullptr) return false;
// Sets *value to the value of the flag. // Sets *value to the value of the flag.
return ParseDouble(std::string("The value of flag --") + flag, value_str, return ParseDouble(std::string("The value of flag --") + flag, value_str,
...@@ -207,13 +207,13 @@ bool ParseStringFlag(const char* str, const char* flag, std::string* value) { ...@@ -207,13 +207,13 @@ bool ParseStringFlag(const char* str, const char* flag, std::string* value) {
const char* const value_str = ParseFlagValue(str, flag, false); const char* const value_str = ParseFlagValue(str, flag, false);
// Aborts if the parsing failed. // Aborts if the parsing failed.
if (value_str == NULL) return false; if (value_str == nullptr) return false;
*value = value_str; *value = value_str;
return true; return true;
} }
bool IsFlag(const char* str, const char* flag) { bool IsFlag(const char* str, const char* flag) {
return (ParseFlagValue(str, flag, true) != NULL); return (ParseFlagValue(str, flag, true) != nullptr);
} }
} // end namespace benchmark } // end namespace benchmark
...@@ -113,13 +113,13 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() { ...@@ -113,13 +113,13 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
} }
#endif #endif
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, nullptr);
return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec; return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
#elif defined(__mips__) #elif defined(__mips__)
// mips apparently only allows rdtsc for superusers, so we fall // mips apparently only allows rdtsc for superusers, so we fall
// back to gettimeofday. It's possible clock_gettime would be better. // back to gettimeofday. It's possible clock_gettime would be better.
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, nullptr);
return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec; return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
#else #else
// The soft failover to a generic implementation is automatic only for ARM. // The soft failover to a generic implementation is automatic only for ARM.
......
...@@ -37,7 +37,7 @@ class Regex { ...@@ -37,7 +37,7 @@ class Regex {
// Compile a regular expression matcher from spec. Returns true on success. // Compile a regular expression matcher from spec. Returns true on success.
// //
// On failure (and if error is not NULL), error is populated with a human // On failure (and if error is not nullptr), error is populated with a human
// readable error message if an error occurs. // readable error message if an error occurs.
bool Init(const std::string& spec, std::string* error); bool Init(const std::string& spec, std::string* error);
......
...@@ -23,7 +23,7 @@ bool Regex::Init(const std::string& spec, std::string* error) { ...@@ -23,7 +23,7 @@ bool Regex::Init(const std::string& spec, std::string* error) {
int ec = regcomp(&re_, spec.c_str(), REG_EXTENDED | REG_NOSUB); int ec = regcomp(&re_, spec.c_str(), REG_EXTENDED | REG_NOSUB);
if (ec != 0) { if (ec != 0) {
if (error) { if (error) {
size_t needed = regerror(ec, &re_, NULL, 0); size_t needed = regerror(ec, &re_, nullptr, 0);
char* errbuf = new char[needed]; char* errbuf = new char[needed];
regerror(ec, &re_, errbuf, needed); regerror(ec, &re_, errbuf, needed);
...@@ -53,7 +53,7 @@ bool Regex::Match(const std::string& str) { ...@@ -53,7 +53,7 @@ bool Regex::Match(const std::string& str) {
return false; return false;
} }
return regexec(&re_, str.c_str(), 0, NULL, 0) == 0; return regexec(&re_, str.c_str(), 0, nullptr, 0) == 0;
} }
} // end namespace benchmark } // end namespace benchmark
...@@ -137,7 +137,7 @@ void InitializeSystemInfo() { ...@@ -137,7 +137,7 @@ void InitializeSystemInfo() {
memmove(line, line + oldlinelen + 1, sizeof(line) - (oldlinelen + 1)); memmove(line, line + oldlinelen + 1, sizeof(line) - (oldlinelen + 1));
// Terminate the new line, reading more if we can't find the newline // Terminate the new line, reading more if we can't find the newline
char* newline = strchr(line, '\n'); char* newline = strchr(line, '\n');
if (newline == NULL) { if (newline == nullptr) {
const size_t linelen = strlen(line); const size_t linelen = strlen(line);
const size_t bytes_to_read = sizeof(line) - 1 - linelen; const size_t bytes_to_read = sizeof(line) - 1 - linelen;
CHECK(bytes_to_read > 0); // because the memmove recovered >=1 bytes CHECK(bytes_to_read > 0); // because the memmove recovered >=1 bytes
...@@ -145,7 +145,7 @@ void InitializeSystemInfo() { ...@@ -145,7 +145,7 @@ void InitializeSystemInfo() {
line[linelen + chars_read] = '\0'; line[linelen + chars_read] = '\0';
newline = strchr(line, '\n'); newline = strchr(line, '\n');
} }
if (newline != NULL) *newline = '\0'; if (newline != nullptr) *newline = '\0';
// When parsing the "cpu MHz" and "bogomips" (fallback) entries, we only // When parsing the "cpu MHz" and "bogomips" (fallback) entries, we only
// accept postive values. Some environments (virtual machines) report zero, // accept postive values. Some environments (virtual machines) report zero,
...@@ -216,7 +216,7 @@ void InitializeSystemInfo() { ...@@ -216,7 +216,7 @@ void InitializeSystemInfo() {
#endif #endif
size_t sz = sizeof(hz); size_t sz = sizeof(hz);
const char* sysctl_path = "machdep.tsc_freq"; const char* sysctl_path = "machdep.tsc_freq";
if (sysctlbyname(sysctl_path, &hz, &sz, NULL, 0) != 0) { if (sysctlbyname(sysctl_path, &hz, &sz, nullptr, 0) != 0) {
fprintf(stderr, "Unable to determine clock rate from sysctl: %s: %s\n", fprintf(stderr, "Unable to determine clock rate from sysctl: %s: %s\n",
sysctl_path, strerror(errno)); sysctl_path, strerror(errno));
cpuinfo_cycles_per_second = EstimateCyclesPerSecond(); cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
...@@ -236,7 +236,7 @@ void InitializeSystemInfo() { ...@@ -236,7 +236,7 @@ void InitializeSystemInfo() {
SUCCEEDED( SUCCEEDED(
SHGetValueA(HKEY_LOCAL_MACHINE, SHGetValueA(HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
"~MHz", NULL, &data, &data_size))) "~MHz", nullptr, &data, &data_size)))
cpuinfo_cycles_per_second = (int64)data * (int64)(1000 * 1000); // was mhz cpuinfo_cycles_per_second = (int64)data * (int64)(1000 * 1000); // was mhz
else else
cpuinfo_cycles_per_second = EstimateCyclesPerSecond(); cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
......
...@@ -177,7 +177,7 @@ std::string Print(WallTime time, const char* format, bool local, ...@@ -177,7 +177,7 @@ std::string Print(WallTime time, const char* format, bool local,
if (!SplitTimezone(time, local, &split, &subsecond)) { if (!SplitTimezone(time, local, &split, &subsecond)) {
snprintf(storage, sizeof(storage), "Invalid time: %f", time); snprintf(storage, sizeof(storage), "Invalid time: %f", time);
} else { } else {
if (remainder_us != NULL) { if (remainder_us != nullptr) {
*remainder_us = static_cast<int>((subsecond * 1000000) + 0.5); *remainder_us = static_cast<int>((subsecond * 1000000) + 0.5);
if (*remainder_us > 999999) *remainder_us = 999999; if (*remainder_us > 999999) *remainder_us = 999999;
if (*remainder_us < 0) *remainder_us = 0; if (*remainder_us < 0) *remainder_us = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment