mirror of https://github.com/google/benchmark.git
Merge null pointer warnings
This commit is contained in:
commit
1924b30a6c
|
@ -39,8 +39,7 @@ add_cxx_compiler_flag(-Wshadow)
|
|||
add_cxx_compiler_flag(-Werror)
|
||||
add_cxx_compiler_flag(-pedantic-errors)
|
||||
add_cxx_compiler_flag(-Wshorten-64-to-32)
|
||||
# TODO(ericwf): enable this for g++
|
||||
#add_cxx_compiler_flag(-Wzero-as-null-pointer-constant)
|
||||
add_cxx_compiler_flag(-Wzero-as-null-pointer-constant)
|
||||
# Release flags
|
||||
add_cxx_compiler_flag(-fno-strict-aliasing RELEASE)
|
||||
|
||||
|
|
|
@ -152,7 +152,8 @@ void Initialize(int* argc, const char** argv);
|
|||
|
||||
// Otherwise, run all benchmarks specified by the --benchmark_filter flag,
|
||||
// and exit after running the benchmarks.
|
||||
void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter = NULL);
|
||||
void RunSpecifiedBenchmarks();
|
||||
void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter);
|
||||
|
||||
// If this routine is called, peak memory allocation past this point in the
|
||||
// benchmark is reported at the end of the benchmark report line. (It is
|
||||
|
@ -164,7 +165,20 @@ void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter = NULL);
|
|||
namespace internal {
|
||||
class Benchmark;
|
||||
class BenchmarkImp;
|
||||
}
|
||||
|
||||
template <class T> struct Voider {
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template <class T, class = void>
|
||||
struct EnableIfString {};
|
||||
|
||||
template <class T>
|
||||
struct EnableIfString<T, typename Voider<typename T::basic_string>::type> {
|
||||
typedef int type;
|
||||
};
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
// State is passed to a running Benchmark and contains state for the
|
||||
// benchmark to use.
|
||||
|
@ -279,7 +293,7 @@ public:
|
|||
// as an injected class name in the case of std::string.
|
||||
template <class StringType>
|
||||
void SetLabel(StringType const & str,
|
||||
typename StringType::basic_string* = 0) {
|
||||
typename internal::EnableIfString<StringType>::type = 1) {
|
||||
this->SetLabel(str.c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -965,6 +965,9 @@ void RunMatchingBenchmarks(const std::string& spec,
|
|||
|
||||
} // end namespace internal
|
||||
|
||||
void RunSpecifiedBenchmarks() {
|
||||
RunSpecifiedBenchmarks(nullptr);
|
||||
}
|
||||
|
||||
void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter) {
|
||||
std::string spec = FLAGS_benchmark_filter;
|
||||
|
|
|
@ -65,7 +65,7 @@ PlatformColorCode GetPlatformColorCode(LogColor color) {
|
|||
case COLOR_WHITE:
|
||||
return "7";
|
||||
default:
|
||||
return NULL;
|
||||
return nullptr;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace benchmark {
|
|||
// unchanged and returns false.
|
||||
bool ParseInt32(const std::string& src_text, const char* str, int32_t* value) {
|
||||
// Parses the environment variable as a decimal integer.
|
||||
char* end = NULL;
|
||||
char* end = nullptr;
|
||||
const long long_value = strtol(str, &end, 10); // NOLINT
|
||||
|
||||
// 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) {
|
|||
// returns true; otherwise leaves *value unchanged and returns false.
|
||||
bool ParseDouble(const std::string& src_text, const char* str, double* value) {
|
||||
// Parses the environment variable as a decimal integer.
|
||||
char* end = NULL;
|
||||
char* end = nullptr;
|
||||
const double double_value = strtod(str, &end); // NOLINT
|
||||
|
||||
// Has strtol() consumed all characters in the string?
|
||||
|
@ -76,9 +76,9 @@ bool ParseDouble(const std::string& src_text, const char* str, double* value) {
|
|||
inline const char* GetEnv(const char* name) {
|
||||
#if defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
|
||||
// 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);
|
||||
return (env != NULL && env[0] != '\0') ? env : NULL;
|
||||
return (env != nullptr && env[0] != '\0') ? env : nullptr;
|
||||
#else
|
||||
return getenv(name);
|
||||
#endif
|
||||
|
@ -104,7 +104,7 @@ static std::string FlagToEnvVar(const char* flag) {
|
|||
bool BoolFromEnv(const char* flag, bool default_value) {
|
||||
const std::string env_var = FlagToEnvVar(flag);
|
||||
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
|
||||
|
@ -113,7 +113,7 @@ bool BoolFromEnv(const char* flag, bool default_value) {
|
|||
int32_t Int32FromEnv(const char* flag, int32_t default_value) {
|
||||
const std::string env_var = FlagToEnvVar(flag);
|
||||
const char* const string_value = GetEnv(env_var.c_str());
|
||||
if (string_value == NULL) {
|
||||
if (string_value == nullptr) {
|
||||
// The environment variable is not set.
|
||||
return 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 std::string env_var = FlagToEnvVar(flag);
|
||||
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
|
||||
// the format "--flag=value". When def_optional is true, the "=value"
|
||||
// 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,
|
||||
bool def_optional) {
|
||||
// str and flag must not be NULL.
|
||||
if (str == NULL || flag == NULL) return NULL;
|
||||
// str and flag must not be nullptr.
|
||||
if (str == nullptr || flag == nullptr) return nullptr;
|
||||
|
||||
// The flag must start with "--".
|
||||
const std::string flag_str = std::string("--") + std::string(flag);
|
||||
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.
|
||||
const char* flag_end = str + flag_len;
|
||||
|
@ -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
|
||||
// flag name, or if def_optional is false, there must be a '=' after
|
||||
// the flag name.
|
||||
if (flag_end[0] != '=') return NULL;
|
||||
if (flag_end[0] != '=') return nullptr;
|
||||
|
||||
// Returns the string after "=".
|
||||
return flag_end + 1;
|
||||
|
@ -171,7 +171,7 @@ bool ParseBoolFlag(const char* str, const char* flag, bool* value) {
|
|||
const char* const value_str = ParseFlagValue(str, flag, true);
|
||||
|
||||
// Aborts if the parsing failed.
|
||||
if (value_str == NULL) return false;
|
||||
if (value_str == nullptr) return false;
|
||||
|
||||
// Converts the string value to a bool.
|
||||
*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) {
|
|||
const char* const value_str = ParseFlagValue(str, flag, false);
|
||||
|
||||
// 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.
|
||||
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) {
|
|||
const char* const value_str = ParseFlagValue(str, flag, false);
|
||||
|
||||
// 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.
|
||||
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) {
|
|||
const char* const value_str = ParseFlagValue(str, flag, false);
|
||||
|
||||
// Aborts if the parsing failed.
|
||||
if (value_str == NULL) return false;
|
||||
if (value_str == nullptr) return false;
|
||||
|
||||
*value = value_str;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsFlag(const char* str, const char* flag) {
|
||||
return (ParseFlagValue(str, flag, true) != NULL);
|
||||
return (ParseFlagValue(str, flag, true) != nullptr);
|
||||
}
|
||||
} // end namespace benchmark
|
||||
|
|
|
@ -113,13 +113,13 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
|
|||
}
|
||||
#endif
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
gettimeofday(&tv, nullptr);
|
||||
return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
|
||||
#elif defined(__mips__)
|
||||
// mips apparently only allows rdtsc for superusers, so we fall
|
||||
// back to gettimeofday. It's possible clock_gettime would be better.
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
gettimeofday(&tv, nullptr);
|
||||
return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
|
||||
#else
|
||||
// The soft failover to a generic implementation is automatic only for ARM.
|
||||
|
|
2
src/re.h
2
src/re.h
|
@ -37,7 +37,7 @@ class Regex {
|
|||
|
||||
// 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.
|
||||
bool 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);
|
||||
if (ec != 0) {
|
||||
if (error) {
|
||||
size_t needed = regerror(ec, &re_, NULL, 0);
|
||||
size_t needed = regerror(ec, &re_, nullptr, 0);
|
||||
char* errbuf = new char[needed];
|
||||
regerror(ec, &re_, errbuf, needed);
|
||||
|
||||
|
@ -53,7 +53,7 @@ bool Regex::Match(const std::string& str) {
|
|||
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
|
||||
|
|
|
@ -137,7 +137,7 @@ void InitializeSystemInfo() {
|
|||
memmove(line, line + oldlinelen + 1, sizeof(line) - (oldlinelen + 1));
|
||||
// Terminate the new line, reading more if we can't find the newline
|
||||
char* newline = strchr(line, '\n');
|
||||
if (newline == NULL) {
|
||||
if (newline == nullptr) {
|
||||
const size_t linelen = strlen(line);
|
||||
const size_t bytes_to_read = sizeof(line) - 1 - linelen;
|
||||
CHECK(bytes_to_read > 0); // because the memmove recovered >=1 bytes
|
||||
|
@ -145,7 +145,7 @@ void InitializeSystemInfo() {
|
|||
line[linelen + chars_read] = '\0';
|
||||
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
|
||||
// accept postive values. Some environments (virtual machines) report zero,
|
||||
|
@ -216,7 +216,7 @@ void InitializeSystemInfo() {
|
|||
#endif
|
||||
size_t sz = sizeof(hz);
|
||||
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",
|
||||
sysctl_path, strerror(errno));
|
||||
cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
|
||||
|
@ -236,7 +236,7 @@ void InitializeSystemInfo() {
|
|||
SUCCEEDED(
|
||||
SHGetValueA(HKEY_LOCAL_MACHINE,
|
||||
"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
|
||||
else
|
||||
cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
|
||||
|
@ -303,7 +303,7 @@ static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
|
|||
cputime_fd = -1;
|
||||
return false;
|
||||
}
|
||||
unsigned long long result = strtoull(buff, NULL, 0);
|
||||
unsigned long long result = strtoull(buff, nullptr, 0);
|
||||
if (result == (std::numeric_limits<unsigned long long>::max)()) {
|
||||
close(cputime_fd);
|
||||
cputime_fd = -1;
|
||||
|
|
|
@ -89,7 +89,7 @@ private:
|
|||
|
||||
WallTime Slow() const {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
gettimeofday(&tv, nullptr);
|
||||
return tv.tv_sec + tv.tv_usec * 1e-6;
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ std::string Print(WallTime time, const char* format, bool local,
|
|||
if (!SplitTimezone(time, local, &split, &subsecond)) {
|
||||
snprintf(storage, sizeof(storage), "Invalid time: %f", time);
|
||||
} else {
|
||||
if (remainder_us != NULL) {
|
||||
if (remainder_us != nullptr) {
|
||||
*remainder_us = static_cast<int>((subsecond * 1000000) + 0.5);
|
||||
if (*remainder_us > 999999) *remainder_us = 999999;
|
||||
if (*remainder_us < 0) *remainder_us = 0;
|
||||
|
|
Loading…
Reference in New Issue