Skip to content

Commit 0acceba

Browse files
Unify UNIX/APPLE environ NULL check
1 parent 4537a8a commit 0acceba

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

rocclr/utils/flags.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,23 @@ bool Flag::init() {
119119
#else // !_WIN32
120120
#ifdef __APPLE__
121121
char** environ = *_NSGetEnviron();
122+
#endif // __APPLE__
123+
122124
if (environ == NULL) {
123125
return false;
124126
}
125-
#endif // __APPLE__
127+
for (const char** p = const_cast<const char**>(environ); *p != NULL; ++p) {
128+
std::string var = *p;
129+
size_t pos = var.find('=');
130+
if ((pos == std::string::npos) || ((pos + 1) > var.size())) {
131+
continue;
132+
}
126133

127-
if (environ != NULL) {
128-
for (const char** p = const_cast<const char**>(environ); *p != NULL; ++p) {
129-
std::string var = *p;
130-
size_t pos = var.find('=');
131-
if ((pos == std::string::npos) || ((pos + 1) > var.size())) {
132-
continue;
133-
}
134-
135-
std::string name = var.substr(0, pos);
136-
if ((pos + 1) == var.size()) {
137-
vars.insert(std::make_pair(name, " "));
138-
} else {
139-
vars.insert(std::make_pair(name, &(*p)[pos + 1]));
140-
}
134+
std::string name = var.substr(0, pos);
135+
if ((pos + 1) == var.size()) {
136+
vars.insert(std::make_pair(name, " "));
137+
} else {
138+
vars.insert(std::make_pair(name, &(*p)[pos + 1]));
141139
}
142140
}
143141
#endif // !_WIN32

0 commit comments

Comments
 (0)