Merge "[libsysutils] Modernize codebase by replacing NULL with nullptr"

am: 1c92fa4480

Change-Id: Ibeda0198208fd195028668270377a6d75154ce4e
This commit is contained in:
Yi Kong 2018-07-24 19:04:47 -07:00 committed by android-build-merger
commit e21533137e
4 changed files with 23 additions and 23 deletions

View file

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

View file

@ -45,8 +45,8 @@ const int LOCAL_NFLOG_PACKET = NFNL_SUBSYS_ULOG << 8 | NFULNL_MSG_PACKET;
NetlinkEvent::NetlinkEvent() {
mAction = Action::kUnknown;
memset(mParams, 0, sizeof(mParams));
mPath = NULL;
mSubsystem = NULL;
mPath = nullptr;
mSubsystem = nullptr;
}
NetlinkEvent::~NetlinkEvent() {
@ -89,7 +89,7 @@ static const char *rtMessageName(int type) {
NL_EVENT_RTM_NAME(LOCAL_QLOG_NL_EVENT);
NL_EVENT_RTM_NAME(LOCAL_NFLOG_PACKET);
default:
return NULL;
return nullptr;
}
#undef NL_EVENT_RTM_NAME
}
@ -158,7 +158,7 @@ bool NetlinkEvent::parseIfInfoMessage(const struct nlmsghdr *nh) {
*/
bool NetlinkEvent::parseIfAddrMessage(const struct nlmsghdr *nh) {
struct ifaddrmsg *ifaddr = (struct ifaddrmsg *) NLMSG_DATA(nh);
struct ifa_cacheinfo *cacheinfo = NULL;
struct ifa_cacheinfo *cacheinfo = nullptr;
char addrstr[INET6_ADDRSTRLEN] = "";
char ifname[IFNAMSIZ] = "";
@ -286,7 +286,7 @@ static uint32_t nlAttrU32(const nlattr* nla) {
bool NetlinkEvent::parseNfPacketMessage(struct nlmsghdr *nh) {
int uid = -1;
int len = 0;
char* raw = NULL;
char* raw = nullptr;
struct nlattr* uid_attr = findNlAttr(nh, sizeof(struct genlmsghdr), NFULA_UID);
if (uid_attr) {
@ -584,7 +584,7 @@ has_prefix(const char* str, const char* end, const char* prefix, size_t prefixle
(prefixlen == 0 || !memcmp(str, prefix, prefixlen))) {
return str + prefixlen;
} else {
return NULL;
return nullptr;
}
}
@ -625,16 +625,16 @@ bool NetlinkEvent::parseAsciiNetlinkMessage(char *buffer, int size) {
first = 0;
} else {
const char* a;
if ((a = HAS_CONST_PREFIX(s, end, "ACTION=")) != NULL) {
if ((a = HAS_CONST_PREFIX(s, end, "ACTION=")) != nullptr) {
if (!strcmp(a, "add"))
mAction = Action::kAdd;
else if (!strcmp(a, "remove"))
mAction = Action::kRemove;
else if (!strcmp(a, "change"))
mAction = Action::kChange;
} else if ((a = HAS_CONST_PREFIX(s, end, "SEQNUM=")) != NULL) {
} else if ((a = HAS_CONST_PREFIX(s, end, "SEQNUM=")) != nullptr) {
mSeq = atoi(a);
} else if ((a = HAS_CONST_PREFIX(s, end, "SUBSYSTEM=")) != NULL) {
} else if ((a = HAS_CONST_PREFIX(s, end, "SUBSYSTEM=")) != nullptr) {
mSubsystem = strdup(a);
} else if (param_idx < NL_PARAMS_MAX) {
mParams[param_idx++] = strdup(s);
@ -656,14 +656,14 @@ bool NetlinkEvent::decode(char *buffer, int size, int format) {
const char *NetlinkEvent::findParam(const char *paramName) {
size_t len = strlen(paramName);
for (int i = 0; i < NL_PARAMS_MAX && mParams[i] != NULL; ++i) {
for (int i = 0; i < NL_PARAMS_MAX && mParams[i] != nullptr; ++i) {
const char *ptr = mParams[i] + len;
if (!strncmp(mParams[i], paramName, len) && *ptr == '=')
return ++ptr;
}
SLOGE("NetlinkEvent::FindParam(): Parameter '%s' not found", paramName);
return NULL;
return nullptr;
}
nlattr* NetlinkEvent::findNlAttr(const nlmsghdr* nh, size_t hdrlen, uint16_t attr) {

View file

@ -42,8 +42,8 @@ void SocketClient::init(int socket, bool owned, bool useCmdNum) {
mSocket = socket;
mSocketOwned = owned;
mUseCmdNum = useCmdNum;
pthread_mutex_init(&mWriteMutex, NULL);
pthread_mutex_init(&mRefCountMutex, NULL);
pthread_mutex_init(&mWriteMutex, nullptr);
pthread_mutex_init(&mRefCountMutex, nullptr);
mPid = -1;
mUid = -1;
mGid = -1;
@ -135,9 +135,9 @@ char *SocketClient::quoteArg(const char *arg) {
const char *end = arg + len;
char *oldresult;
if(result == NULL) {
if(result == nullptr) {
SLOGW("malloc error (%s)", strerror(errno));
return NULL;
return nullptr;
}
*(current++) = '"';

View file

@ -39,7 +39,7 @@ SocketListener::SocketListener(const char *socketName, bool listen) {
}
SocketListener::SocketListener(int socketFd, bool listen) {
init(NULL, socketFd, listen, false);
init(nullptr, socketFd, listen, false);
}
SocketListener::SocketListener(const char *socketName, bool listen, bool useCmdNum) {
@ -51,7 +51,7 @@ void SocketListener::init(const char *socketName, int socketFd, bool listen, boo
mSocketName = socketName;
mSock = socketFd;
mUseCmdNum = useCmdNum;
pthread_mutex_init(&mClientsLock, NULL);
pthread_mutex_init(&mClientsLock, nullptr);
mClients = new SocketClientCollection();
}
@ -102,7 +102,7 @@ int SocketListener::startListener(int backlog) {
return -1;
}
if (pthread_create(&mThread, NULL, SocketListener::threadStart, this)) {
if (pthread_create(&mThread, nullptr, SocketListener::threadStart, this)) {
SLOGE("pthread_create (%s)", strerror(errno));
return -1;
}
@ -147,8 +147,8 @@ void *SocketListener::threadStart(void *obj) {
SocketListener *me = reinterpret_cast<SocketListener *>(obj);
me->runListener();
pthread_exit(NULL);
return NULL;
pthread_exit(nullptr);
return nullptr;
}
void SocketListener::runListener() {
@ -183,7 +183,7 @@ void SocketListener::runListener() {
}
pthread_mutex_unlock(&mClientsLock);
SLOGV("mListen=%d, max=%d, mSocketName=%s", mListen, max, mSocketName);
if ((rc = select(max + 1, &read_fds, NULL, NULL, NULL)) < 0) {
if ((rc = select(max + 1, &read_fds, nullptr, nullptr, nullptr)) < 0) {
if (errno == EINTR)
continue;
SLOGE("select failed (%s) mListen=%d, max=%d", strerror(errno), mListen, max);