Convert to C++ nullptr from NULL.

This commit is contained in:
Jonathan Naylor
2025-03-14 12:13:11 +00:00
parent 43f8b2f6f0
commit cf15f42a0f
98 changed files with 1340 additions and 1340 deletions

View File

@@ -69,11 +69,11 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
::strcpy((char*)info, "(address unknown)");
#if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__APPLE__)
char* dflt = NULL;
char* dflt = nullptr;
#if defined(__linux__)
FILE* fp = ::fopen("/proc/net/route" , "r"); // IPv4 routing
if (fp == NULL) {
if (fp == nullptr) {
LogError("Unabled to open /proc/route");
return;
}
@@ -81,9 +81,9 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
char line[100U];
while (::fgets(line, 100U, fp)) {
char* p1 = strtok(line , " \t");
char* p2 = strtok(NULL , " \t");
char* p2 = strtok(nullptr , " \t");
if (p1 != NULL && p2 != NULL) {
if (p1 != nullptr && p2 != nullptr) {
if (::strcmp(p2, "00000000") == 0) {
dflt = p1;
break;
@@ -109,13 +109,13 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
size_t size;
char ifname[IF_NAMESIZE] = {};
if (::sysctl(mib, cnt, NULL, &size, NULL, 0) == -1 || size <= 0) {
if (::sysctl(mib, cnt, nullptr, &size, nullptr, 0) == -1 || size <= 0) {
LogError("Unable to estimate routing table size");
return;
}
char *buf = new char[size];
if (::sysctl(mib, cnt, buf, &size, NULL, 0) == -1) {
if (::sysctl(mib, cnt, buf, &size, nullptr, 0) == -1) {
LogError("Unable to get routing table");
delete[] buf;
return;
@@ -141,7 +141,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
if (::strlen(ifname))
dflt = ifname;
#endif
if (dflt == NULL) {
if (dflt == nullptr) {
LogError("Unable to find the default route");
return;
}
@@ -158,14 +158,14 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
}
unsigned int ifnr = 0U;
for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == NULL)
for (struct ifaddrs* ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == nullptr)
continue;
int family = ifa->ifa_addr->sa_family;
if (family == AF_INET || family == AF_INET6) {
char host[NI_MAXHOST];
int s = ::getnameinfo(ifa->ifa_addr, family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
int s = ::getnameinfo(ifa->ifa_addr, family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), host, NI_MAXHOST, nullptr, 0, NI_NUMERICHOST);
if (s != 0) {
LogError("getnameinfo() failed: %s\n", gai_strerror(s));
continue;
@@ -190,7 +190,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
for (unsigned int n = 0U; n < ifnr; n++) {
char* p = ::strchr(interfacelist[n], '%');
if (p != NULL)
if (p != nullptr)
*p = 0;
if (::strstr(interfacelist[n], dflt) != 0) {
@@ -202,7 +202,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
LogInfo(" IP to show: %s", info);
#elif defined(_WIN32) || defined(_WIN64)
PMIB_IPFORWARDTABLE pIpForwardTable = (MIB_IPFORWARDTABLE *)::malloc(sizeof(MIB_IPFORWARDTABLE));
if (pIpForwardTable == NULL) {
if (pIpForwardTable == nullptr) {
LogError("Error allocating memory");
return;
}
@@ -211,7 +211,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
if (::GetIpForwardTable(pIpForwardTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
::free(pIpForwardTable);
pIpForwardTable = (MIB_IPFORWARDTABLE *)::malloc(dwSize);
if (pIpForwardTable == NULL) {
if (pIpForwardTable == nullptr) {
LogError("Error allocating memory");
return;
}
@@ -242,7 +242,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
::free(pIpForwardTable);
PIP_ADAPTER_INFO pAdapterInfo = (IP_ADAPTER_INFO *)::malloc(sizeof(IP_ADAPTER_INFO));
if (pAdapterInfo == NULL) {
if (pAdapterInfo == nullptr) {
LogError("Error allocating memory");
return;
}
@@ -251,7 +251,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
if (::GetAdaptersInfo(pAdapterInfo, &buflen) == ERROR_BUFFER_OVERFLOW) {
::free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *)::malloc(buflen);
if (pAdapterInfo == NULL) {
if (pAdapterInfo == nullptr) {
LogError("Error allocating memory");
return;
}
@@ -264,7 +264,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
}
PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
while (pAdapter != NULL) {
while (pAdapter != nullptr) {
LogInfo(" IP : %s", pAdapter->IpAddressList.IpAddress.String);
if (pAdapter->Index == ifnr)
::strcpy((char*)info, pAdapter->IpAddressList.IpAddress.String);