Skip to content

Commit 1c92fa4

Browse files
Treehugger RobotGerrit Code Review
Treehugger Robot
authored and
Gerrit Code Review
committed
Merge "[libsysutils] Modernize codebase by replacing NULL with nullptr"
2 parents 2efcb52 + 4888525 commit 1c92fa4

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

libsysutils/src/FrameworkListener.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ FrameworkListener::FrameworkListener(const char *socketName) :
4242

4343
FrameworkListener::FrameworkListener(int sock) :
4444
SocketListener(sock, true) {
45-
init(NULL, false);
45+
init(nullptr, false);
4646
}
4747

4848
void FrameworkListener::init(const char *socketName UNUSED, bool withSeq) {
@@ -154,7 +154,7 @@ void FrameworkListener::dispatchCommand(SocketClient *cli, char *data) {
154154
if (!haveCmdNum) {
155155
char *endptr;
156156
int cmdNum = (int)strtol(tmp, &endptr, 0);
157-
if (endptr == NULL || *endptr != '\0') {
157+
if (endptr == nullptr || *endptr != '\0') {
158158
cli->sendMsg(500, "Invalid sequence number", false);
159159
goto out;
160160
}

libsysutils/src/NetlinkEvent.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const int LOCAL_NFLOG_PACKET = NFNL_SUBSYS_ULOG << 8 | NFULNL_MSG_PACKET;
4545
NetlinkEvent::NetlinkEvent() {
4646
mAction = Action::kUnknown;
4747
memset(mParams, 0, sizeof(mParams));
48-
mPath = NULL;
49-
mSubsystem = NULL;
48+
mPath = nullptr;
49+
mSubsystem = nullptr;
5050
}
5151

5252
NetlinkEvent::~NetlinkEvent() {
@@ -89,7 +89,7 @@ static const char *rtMessageName(int type) {
8989
NL_EVENT_RTM_NAME(LOCAL_QLOG_NL_EVENT);
9090
NL_EVENT_RTM_NAME(LOCAL_NFLOG_PACKET);
9191
default:
92-
return NULL;
92+
return nullptr;
9393
}
9494
#undef NL_EVENT_RTM_NAME
9595
}
@@ -158,7 +158,7 @@ bool NetlinkEvent::parseIfInfoMessage(const struct nlmsghdr *nh) {
158158
*/
159159
bool NetlinkEvent::parseIfAddrMessage(const struct nlmsghdr *nh) {
160160
struct ifaddrmsg *ifaddr = (struct ifaddrmsg *) NLMSG_DATA(nh);
161-
struct ifa_cacheinfo *cacheinfo = NULL;
161+
struct ifa_cacheinfo *cacheinfo = nullptr;
162162
char addrstr[INET6_ADDRSTRLEN] = "";
163163
char ifname[IFNAMSIZ] = "";
164164

@@ -286,7 +286,7 @@ static uint32_t nlAttrU32(const nlattr* nla) {
286286
bool NetlinkEvent::parseNfPacketMessage(struct nlmsghdr *nh) {
287287
int uid = -1;
288288
int len = 0;
289-
char* raw = NULL;
289+
char* raw = nullptr;
290290

291291
struct nlattr* uid_attr = findNlAttr(nh, sizeof(struct genlmsghdr), NFULA_UID);
292292
if (uid_attr) {
@@ -584,7 +584,7 @@ has_prefix(const char* str, const char* end, const char* prefix, size_t prefixle
584584
(prefixlen == 0 || !memcmp(str, prefix, prefixlen))) {
585585
return str + prefixlen;
586586
} else {
587-
return NULL;
587+
return nullptr;
588588
}
589589
}
590590

@@ -625,16 +625,16 @@ bool NetlinkEvent::parseAsciiNetlinkMessage(char *buffer, int size) {
625625
first = 0;
626626
} else {
627627
const char* a;
628-
if ((a = HAS_CONST_PREFIX(s, end, "ACTION=")) != NULL) {
628+
if ((a = HAS_CONST_PREFIX(s, end, "ACTION=")) != nullptr) {
629629
if (!strcmp(a, "add"))
630630
mAction = Action::kAdd;
631631
else if (!strcmp(a, "remove"))
632632
mAction = Action::kRemove;
633633
else if (!strcmp(a, "change"))
634634
mAction = Action::kChange;
635-
} else if ((a = HAS_CONST_PREFIX(s, end, "SEQNUM=")) != NULL) {
635+
} else if ((a = HAS_CONST_PREFIX(s, end, "SEQNUM=")) != nullptr) {
636636
mSeq = atoi(a);
637-
} else if ((a = HAS_CONST_PREFIX(s, end, "SUBSYSTEM=")) != NULL) {
637+
} else if ((a = HAS_CONST_PREFIX(s, end, "SUBSYSTEM=")) != nullptr) {
638638
mSubsystem = strdup(a);
639639
} else if (param_idx < NL_PARAMS_MAX) {
640640
mParams[param_idx++] = strdup(s);
@@ -656,14 +656,14 @@ bool NetlinkEvent::decode(char *buffer, int size, int format) {
656656

657657
const char *NetlinkEvent::findParam(const char *paramName) {
658658
size_t len = strlen(paramName);
659-
for (int i = 0; i < NL_PARAMS_MAX && mParams[i] != NULL; ++i) {
659+
for (int i = 0; i < NL_PARAMS_MAX && mParams[i] != nullptr; ++i) {
660660
const char *ptr = mParams[i] + len;
661661
if (!strncmp(mParams[i], paramName, len) && *ptr == '=')
662662
return ++ptr;
663663
}
664664

665665
SLOGE("NetlinkEvent::FindParam(): Parameter '%s' not found", paramName);
666-
return NULL;
666+
return nullptr;
667667
}
668668

669669
nlattr* NetlinkEvent::findNlAttr(const nlmsghdr* nh, size_t hdrlen, uint16_t attr) {

libsysutils/src/SocketClient.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ void SocketClient::init(int socket, bool owned, bool useCmdNum) {
4242
mSocket = socket;
4343
mSocketOwned = owned;
4444
mUseCmdNum = useCmdNum;
45-
pthread_mutex_init(&mWriteMutex, NULL);
46-
pthread_mutex_init(&mRefCountMutex, NULL);
45+
pthread_mutex_init(&mWriteMutex, nullptr);
46+
pthread_mutex_init(&mRefCountMutex, nullptr);
4747
mPid = -1;
4848
mUid = -1;
4949
mGid = -1;
@@ -135,9 +135,9 @@ char *SocketClient::quoteArg(const char *arg) {
135135
const char *end = arg + len;
136136
char *oldresult;
137137

138-
if(result == NULL) {
138+
if(result == nullptr) {
139139
SLOGW("malloc error (%s)", strerror(errno));
140-
return NULL;
140+
return nullptr;
141141
}
142142

143143
*(current++) = '"';

libsysutils/src/SocketListener.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ SocketListener::SocketListener(const char *socketName, bool listen) {
3939
}
4040

4141
SocketListener::SocketListener(int socketFd, bool listen) {
42-
init(NULL, socketFd, listen, false);
42+
init(nullptr, socketFd, listen, false);
4343
}
4444

4545
SocketListener::SocketListener(const char *socketName, bool listen, bool useCmdNum) {
@@ -51,7 +51,7 @@ void SocketListener::init(const char *socketName, int socketFd, bool listen, boo
5151
mSocketName = socketName;
5252
mSock = socketFd;
5353
mUseCmdNum = useCmdNum;
54-
pthread_mutex_init(&mClientsLock, NULL);
54+
pthread_mutex_init(&mClientsLock, nullptr);
5555
mClients = new SocketClientCollection();
5656
}
5757

@@ -102,7 +102,7 @@ int SocketListener::startListener(int backlog) {
102102
return -1;
103103
}
104104

105-
if (pthread_create(&mThread, NULL, SocketListener::threadStart, this)) {
105+
if (pthread_create(&mThread, nullptr, SocketListener::threadStart, this)) {
106106
SLOGE("pthread_create (%s)", strerror(errno));
107107
return -1;
108108
}
@@ -147,8 +147,8 @@ void *SocketListener::threadStart(void *obj) {
147147
SocketListener *me = reinterpret_cast<SocketListener *>(obj);
148148

149149
me->runListener();
150-
pthread_exit(NULL);
151-
return NULL;
150+
pthread_exit(nullptr);
151+
return nullptr;
152152
}
153153

154154
void SocketListener::runListener() {
@@ -183,7 +183,7 @@ void SocketListener::runListener() {
183183
}
184184
pthread_mutex_unlock(&mClientsLock);
185185
SLOGV("mListen=%d, max=%d, mSocketName=%s", mListen, max, mSocketName);
186-
if ((rc = select(max + 1, &read_fds, NULL, NULL, NULL)) < 0) {
186+
if ((rc = select(max + 1, &read_fds, nullptr, nullptr, nullptr)) < 0) {
187187
if (errno == EINTR)
188188
continue;
189189
SLOGE("select failed (%s) mListen=%d, max=%d", strerror(errno), mListen, max);

0 commit comments

Comments
 (0)