Skip to content

Commit deb1006

Browse files
Vertexwahnlarsrc-google
authored andcommitted
Cleanup: Replace NULL with nullptr
At several places, NULL and nullptr were mixed. This commit cleans this up and switches NULL to nullptr where appropriate. Closes bazelbuild#13168. PiperOrigin-RevId: 362043567
1 parent ed0100b commit deb1006

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+441
-432
lines changed

examples/windows/dll/hello_world-load-dll-at-runtime.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ int main() {
1212

1313
hellolib = LoadLibrary(TEXT("hellolib.dll"));
1414

15-
if (hellolib != NULL) {
15+
if (hellolib != nullptr) {
1616
get_time = (GET_TIME_PTR)GetProcAddress(hellolib, "get_time");
1717
say_hello = (SAY_HELLO_PTR)GetProcAddress(hellolib, "say_hello");
1818

19-
if (NULL != get_time && NULL != say_hello) {
19+
if (nullptr != get_time && nullptr != say_hello) {
2020
success = TRUE;
2121
char *now = get_time();
2222
say_hello(now);

src/main/cpp/archive_utils.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct PartialZipExtractor : public devtools_ijar::ZipExtractorProcessor {
3737

3838
// Scan the zip file "archive_path" until a file named "stop_entry" is seen,
3939
// then stop.
40-
// If entry_names is not null, it receives a list of all file members
40+
// If entry_names is not nullptr, it receives a list of all file members
4141
// up to and including "stop_entry".
4242
// If a callback is given, it is run with the name and contents of
4343
// each such member.

src/main/cpp/blaze.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ static void WriteFileToStderrOrDie(const blaze_util::Path &path) {
737737
FILE *fp = fopen(path.AsNativePath().c_str(), "r");
738738
#endif
739739

740-
if (fp == NULL) {
740+
if (fp == nullptr) {
741741
BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
742742
<< "opening " << path.AsPrintablePath()
743743
<< " failed: " << GetLastErrorString();
@@ -1383,7 +1383,7 @@ static map<string, EnvVarValue> PrepareEnvironmentForJvm() {
13831383
// environment variables to modify the current process, we may actually use
13841384
// such map to configure a process from scratch (via interfaces like execvpe
13851385
// or posix_spawn), so we need to inherit any untouched variables.
1386-
for (char **entry = environ; *entry != NULL; entry++) {
1386+
for (char **entry = environ; *entry != nullptr; entry++) {
13871387
const std::string var_value = *entry;
13881388
std::string::size_type equals = var_value.find('=');
13891389
if (equals == std::string::npos) {
@@ -2085,7 +2085,7 @@ unsigned int BlazeServer::Communicate(
20852085

20862086
// Execute the requested program, but before doing so, flush everything
20872087
// we still have to say.
2088-
fflush(NULL);
2088+
fflush(nullptr);
20892089
ExecuteRunRequest(blaze_util::Path(request.argv(0)), argv);
20902090
}
20912091

src/main/cpp/blaze_util.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ const char* GetUnaryOption(const char *arg,
5151
const char *next_arg,
5252
const char *key) {
5353
const char *value = blaze_util::var_strprefix(arg, key);
54-
if (value == NULL) {
55-
return NULL;
54+
if (value == nullptr) {
55+
return nullptr;
5656
} else if (value[0] == '=') {
5757
return value + 1;
5858
} else if (value[0]) {
59-
return NULL; // trailing garbage in key name
59+
return nullptr; // trailing garbage in key name
6060
}
6161

6262
return next_arg;
6363
}
6464

6565
bool GetNullaryOption(const char *arg, const char *key) {
6666
const char *value = blaze_util::var_strprefix(arg, key);
67-
if (value == NULL) {
67+
if (value == nullptr) {
6868
return false;
6969
} else if (value[0] == '=') {
7070
BAZEL_DIE(blaze_exit_code::BAD_ARGV)
@@ -114,7 +114,7 @@ std::vector<std::string> GetAllUnaryOptionValues(
114114
const char* SearchUnaryOption(const vector<string>& args,
115115
const char *key, bool warn_if_dupe) {
116116
if (args.empty()) {
117-
return NULL;
117+
return nullptr;
118118
}
119119

120120
const char* value = nullptr;
@@ -138,7 +138,7 @@ const char* SearchUnaryOption(const vector<string>& args,
138138
const char* result = GetUnaryOption(args[i].c_str(),
139139
args[i + 1].c_str(),
140140
key);
141-
if (result != NULL) {
141+
if (result != nullptr) {
142142
// 'key' was found and 'result' has its value.
143143
if (value) {
144144
// 'key' was found once before, because 'value' is not empty.
@@ -158,7 +158,7 @@ const char* SearchUnaryOption(const vector<string>& args,
158158
if (!found_dupe) {
159159
// We did not find a duplicate in the first N-1 arguments. Examine the
160160
// last argument, it may be a duplicate.
161-
found_dupe = (GetUnaryOption(args[i].c_str(), NULL, key) != nullptr);
161+
found_dupe = (GetUnaryOption(args[i].c_str(), nullptr, key) != nullptr);
162162
}
163163
if (found_dupe) {
164164
BAZEL_LOG(WARNING) << key << " is given more than once, "
@@ -170,7 +170,7 @@ const char* SearchUnaryOption(const vector<string>& args,
170170
// 'value' is empty, so 'key' was not yet found in the first N-1 arguments.
171171
// If 'key' is in the last argument, we'll parse and return the value from
172172
// that, and if it isn't, we'll return NULL.
173-
return GetUnaryOption(args[i].c_str(), NULL, key);
173+
return GetUnaryOption(args[i].c_str(), nullptr, key);
174174
}
175175
}
176176

src/main/cpp/blaze_util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool GetNullaryOption(const char *arg, const char *key);
4949
// When 'warn_if_dupe' is true, the method checks if 'key' is specified more
5050
// than once and prints a warning if so.
5151
// Returns the value of the 'key' flag iff it occurs in args.
52-
// Returns NULL otherwise.
52+
// Returns nullptr otherwise.
5353
const char* SearchUnaryOption(const std::vector<std::string>& args,
5454
const char* key, bool warn_if_dupe);
5555

src/main/cpp/blaze_util_bsd.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ using std::string;
6363
string GetOutputRoot() {
6464
char buf[2048];
6565
struct passwd pwbuf;
66-
struct passwd *pw = NULL;
66+
struct passwd *pw = nullptr;
6767
int uid = getuid();
6868
int r = getpwuid_r(uid, &pwbuf, buf, 2048, &pw);
69-
if (r != -1 && pw != NULL) {
69+
if (r != -1 && pw != nullptr) {
7070
return blaze_util::JoinPath(pw->pw_dir, ".cache/bazel");
7171
} else {
7272
return "/tmp";

src/main/cpp/blaze_util_darwin.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ using std::string;
4949
using std::vector;
5050

5151
// A stack based class for RAII type handling of CF based types that need
52-
// CFRelease called on them. Checks for NULL before calling release.
52+
// CFRelease called on them. Checks for nullptr before calling release.
5353
template <typename T> class CFScopedReleaser {
5454
public:
5555
explicit CFScopedReleaser(T value) : value_(value) { }
@@ -60,7 +60,7 @@ template <typename T> class CFScopedReleaser {
6060
}
6161
T get() { return value_; }
6262
operator T() { return value_; }
63-
bool isValid() { return value_ != NULL; }
63+
bool isValid() { return value_ != nullptr; }
6464

6565
private:
6666
T value_;
@@ -105,8 +105,8 @@ void WarnFilesystemType(const blaze_util::Path &output_base) {
105105
kCFAllocatorDefault,
106106
reinterpret_cast<const UInt8 *>(output_base.AsNativePath().c_str()),
107107
output_base.AsNativePath().length(), true));
108-
CFBooleanRef cf_local = NULL;
109-
CFErrorRef cf_error = NULL;
108+
CFBooleanRef cf_local = nullptr;
109+
CFErrorRef cf_error = nullptr;
110110
if (!cf_url.isValid() ||
111111
!CFURLCopyResourcePropertyForKey(cf_url, kCFURLVolumeIsLocalKey,
112112
&cf_local, &cf_error)) {
@@ -136,7 +136,7 @@ string GetSelfPath(const char* argv0) {
136136

137137
uint64_t GetMillisecondsMonotonic() {
138138
struct timeval ts = {};
139-
if (gettimeofday(&ts, NULL) < 0) {
139+
if (gettimeofday(&ts, nullptr) < 0) {
140140
BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
141141
<< "error calling gettimeofday: " << GetLastErrorString();
142142
}
@@ -178,14 +178,14 @@ string GetSystemJavabase() {
178178

179179
// java_home will print a warning if no JDK could be found
180180
FILE *output = popen("/usr/libexec/java_home -v 1.8+ 2> /dev/null", "r");
181-
if (output == NULL) {
181+
if (output == nullptr) {
182182
return "";
183183
}
184184

185185
char buf[512];
186186
char *result = fgets(buf, sizeof(buf), output);
187187
pclose(output);
188-
if (result == NULL) {
188+
if (result == nullptr) {
189189
return "";
190190
}
191191

@@ -225,7 +225,7 @@ void ExcludePathFromBackup(const blaze_util::Path &path) {
225225
<< "' from backups";
226226
return;
227227
}
228-
CFErrorRef cf_error = NULL;
228+
CFErrorRef cf_error = nullptr;
229229
if (!CFURLSetResourcePropertyForKey(cf_url, kCFURLIsExcludedFromBackupKey,
230230
kCFBooleanTrue, &cf_error)) {
231231
CFScopedReleaser<CFErrorRef> cf_error_releaser(cf_error);

src/main/cpp/blaze_util_linux.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ string GetOutputRoot() {
5151
} else {
5252
char buf[2048];
5353
struct passwd pwbuf;
54-
struct passwd *pw = NULL;
54+
struct passwd *pw = nullptr;
5555
int uid = getuid();
5656
int r = getpwuid_r(uid, &pwbuf, buf, 2048, &pw);
57-
if (r != -1 && pw != NULL) {
57+
if (r != -1 && pw != nullptr) {
5858
base = pw->pw_dir;
5959
}
6060
}
@@ -152,7 +152,7 @@ string GetSystemJavabase() {
152152

153153
// Resolve all symlinks.
154154
char resolved_path[PATH_MAX];
155-
if (realpath(javac_dir.c_str(), resolved_path) == NULL) {
155+
if (realpath(javac_dir.c_str(), resolved_path) == nullptr) {
156156
return "";
157157
}
158158
javac_dir = resolved_path;

src/main/cpp/blaze_util_posix.cc

+10-12
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void SignalHandler::Install(const string& product_name,
190190
// Unblock all signals.
191191
sigset_t sigset;
192192
sigemptyset(&sigset);
193-
sigprocmask(SIG_SETMASK, &sigset, NULL);
193+
sigprocmask(SIG_SETMASK, &sigset, nullptr);
194194

195195
signal(SIGINT, handler);
196196
signal(SIGTERM, handler);
@@ -255,7 +255,7 @@ class CharPP {
255255
for (; i < args.size(); i++) {
256256
charpp_[i] = strdup(args[i].c_str());
257257
}
258-
charpp_[i] = NULL;
258+
charpp_[i] = nullptr;
259259
}
260260

261261
// Constructs a new CharPP from a list of environment variables.
@@ -279,12 +279,12 @@ class CharPP {
279279
assert(false);
280280
}
281281
}
282-
charpp_[i] = NULL;
282+
charpp_[i] = nullptr;
283283
}
284284

285285
// Deletes all memory held by the CharPP.
286286
~CharPP() {
287-
for (char** ptr = charpp_; *ptr != NULL; ptr++) {
287+
for (char** ptr = charpp_; *ptr != nullptr; ptr++) {
288288
free(*ptr);
289289
}
290290
free(charpp_);
@@ -532,14 +532,12 @@ void CreateSecureOutputRoot(const blaze_util::Path& path) {
532532

533533
string GetEnv(const string& name) {
534534
char* result = getenv(name.c_str());
535-
return result != NULL ? string(result) : "";
535+
return result != nullptr ? string(result) : "";
536536
}
537537

538538
string GetPathEnv(const string& name) { return GetEnv(name); }
539539

540-
bool ExistsEnv(const string& name) {
541-
return getenv(name.c_str()) != NULL;
542-
}
540+
bool ExistsEnv(const string& name) { return getenv(name.c_str()) != nullptr; }
543541

544542
void SetEnv(const string& name, const string& value) {
545543
setenv(name.c_str(), value.c_str(), 1);
@@ -558,8 +556,8 @@ void SetupStdStreams() {
558556
// output (when for example a query returns results as proto), in which case
559557
// we must not perform line buffering on the client side. So turn off
560558
// buffering here completely.
561-
setvbuf(stdout, NULL, _IONBF, 0);
562-
setvbuf(stderr, NULL, _IONBF, 0);
559+
setvbuf(stdout, nullptr, _IONBF, 0);
560+
setvbuf(stderr, nullptr, _IONBF, 0);
563561

564562
// Ensure we have three open fds. Otherwise we can end up with
565563
// bizarre things like stdout going to the lock file, etc.
@@ -736,7 +734,7 @@ void TrySleep(unsigned int milliseconds) {
736734
time_t seconds_part = (time_t)(milliseconds / 1000);
737735
long nanoseconds_part = ((long)(milliseconds % 1000)) * 1000 * 1000;
738736
struct timespec sleeptime = {seconds_part, nanoseconds_part};
739-
nanosleep(&sleeptime, NULL);
737+
nanosleep(&sleeptime, nullptr);
740738
}
741739

742740
string GetUserName() {
@@ -746,7 +744,7 @@ string GetUserName() {
746744
}
747745
errno = 0;
748746
passwd *pwent = getpwuid(getuid()); // NOLINT (single-threaded)
749-
if (pwent == NULL || pwent->pw_name == NULL) {
747+
if (pwent == nullptr || pwent->pw_name == nullptr) {
750748
BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
751749
<< "$USER is not set, and unable to look up name of current user: "
752750
<< GetLastErrorString();

0 commit comments

Comments
 (0)