clang-tidy nullptr

This commit is contained in:
Erik Frojdh 2020-06-10 08:27:35 +02:00
parent f5160b0978
commit 265e96d675
2 changed files with 25 additions and 25 deletions

View File

@ -46,19 +46,19 @@ void BinaryFile::CreateFile() {
currentFileName = os.str(); currentFileName = os.str();
if (!(*overWriteEnable)) { if (!(*overWriteEnable)) {
if (NULL == if (nullptr ==
(filefd = fopen((const char *)currentFileName.c_str(), "wx"))) { (filefd = fopen((const char *)currentFileName.c_str(), "wx"))) {
filefd = 0; filefd = nullptr;
throw sls::RuntimeError("Could not create/overwrite file " + throw sls::RuntimeError("Could not create/overwrite file " +
currentFileName); currentFileName);
} }
} else if (NULL == } else if (nullptr ==
(filefd = fopen((const char *)currentFileName.c_str(), "w"))) { (filefd = fopen((const char *)currentFileName.c_str(), "w"))) {
filefd = 0; filefd = nullptr;
throw sls::RuntimeError("Could not create file " + currentFileName); throw sls::RuntimeError("Could not create file " + currentFileName);
} }
// setting to no file buffering // setting to no file buffering
setvbuf(filefd, NULL, _IONBF, 0); setvbuf(filefd, nullptr, _IONBF, 0);
if (!(*silentMode)) { if (!(*silentMode)) {
LOG(logINFO) << "[" << *udpPortNumber LOG(logINFO) << "[" << *udpPortNumber
@ -69,7 +69,7 @@ void BinaryFile::CreateFile() {
void BinaryFile::CloseCurrentFile() { void BinaryFile::CloseCurrentFile() {
if (filefd) if (filefd)
fclose(filefd); fclose(filefd);
filefd = 0; filefd = nullptr;
} }
void BinaryFile::CloseAllFiles() { void BinaryFile::CloseAllFiles() {
@ -77,7 +77,7 @@ void BinaryFile::CloseAllFiles() {
if (master) { if (master) {
if (masterfd) if (masterfd)
fclose(masterfd); fclose(masterfd);
masterfd = 0; masterfd = nullptr;
} }
} }
@ -153,22 +153,22 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable,
// create master file // create master file
if (!(*overWriteEnable)) { if (!(*overWriteEnable)) {
if (NULL == (masterfd = fopen((const char *)masterFileName.c_str(), if (nullptr == (masterfd = fopen((const char *)masterFileName.c_str(),
"wx"))) { "wx"))) {
masterfd = 0; masterfd = nullptr;
throw sls::RuntimeError("Could not create binary master file " throw sls::RuntimeError("Could not create binary master file "
"(without overwrite enable) " + "(without overwrite enable) " +
masterFileName); masterFileName);
} }
} else if (NULL == (masterfd = fopen( } else if (nullptr == (masterfd = fopen(
(const char *)masterFileName.c_str(), "w"))) { (const char *)masterFileName.c_str(), "w"))) {
masterfd = 0; masterfd = nullptr;
throw sls::RuntimeError("Could not create binary master file " throw sls::RuntimeError("Could not create binary master file "
"(with overwrite enable) " + "(with overwrite enable) " +
masterFileName); masterFileName);
} }
// create master file data // create master file data
time_t t = time(0); time_t t = time(nullptr);
char message[maxMasterFileSize]; char message[maxMasterFileSize];
sprintf(message, sprintf(message,
"Version : %.1f\n" "Version : %.1f\n"
@ -252,6 +252,6 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable,
} }
if (masterfd) if (masterfd)
fclose(masterfd); fclose(masterfd);
masterfd = 0; masterfd = nullptr;
} }
} }

View File

@ -33,12 +33,12 @@ ZmqSocket::ZmqSocket(const char *const hostname_or_ip,
// create context // create context
sockfd.contextDescriptor = zmq_ctx_new(); sockfd.contextDescriptor = zmq_ctx_new();
if (sockfd.contextDescriptor == 0) if (sockfd.contextDescriptor == nullptr)
throw sls::ZmqSocketError("Could not create contextDescriptor"); throw sls::ZmqSocketError("Could not create contextDescriptor");
// create publisher // create publisher
sockfd.socketDescriptor = zmq_socket(sockfd.contextDescriptor, ZMQ_SUB); sockfd.socketDescriptor = zmq_socket(sockfd.contextDescriptor, ZMQ_SUB);
if (sockfd.socketDescriptor == 0) { if (sockfd.socketDescriptor == nullptr) {
PrintError(); PrintError();
Close(); Close();
throw sls::ZmqSocketError("Could not create socket"); throw sls::ZmqSocketError("Could not create socket");
@ -73,11 +73,11 @@ ZmqSocket::ZmqSocket(const uint32_t portnumber, const char *ethip)
// create context // create context
sockfd.contextDescriptor = zmq_ctx_new(); sockfd.contextDescriptor = zmq_ctx_new();
if (sockfd.contextDescriptor == 0) if (sockfd.contextDescriptor == nullptr)
throw sls::ZmqSocketError("Could not create contextDescriptor"); throw sls::ZmqSocketError("Could not create contextDescriptor");
// create publisher // create publisher
sockfd.socketDescriptor = zmq_socket(sockfd.contextDescriptor, ZMQ_PUB); sockfd.socketDescriptor = zmq_socket(sockfd.contextDescriptor, ZMQ_PUB);
if (sockfd.socketDescriptor == 0) { if (sockfd.socketDescriptor == nullptr) {
PrintError(); PrintError();
Close(); Close();
throw sls::ZmqSocketError("Could not create socket"); throw sls::ZmqSocketError("Could not create socket");
@ -117,12 +117,12 @@ int ZmqSocket::ConvertHostnameToInternetAddress(const char *const hostname,
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
// get host info into res // get host info into res
int errcode = getaddrinfo(hostname, NULL, &hints, res); int errcode = getaddrinfo(hostname, nullptr, &hints, res);
if (errcode != 0) { if (errcode != 0) {
LOG(logERROR) << "Error: Could not convert hostname " << hostname LOG(logERROR) << "Error: Could not convert hostname " << hostname
<< " to internet address (zmq):" << gai_strerror(errcode); << " to internet address (zmq):" << gai_strerror(errcode);
} else { } else {
if (*res == NULL) { if (*res == nullptr) {
LOG(logERROR) << "Could not convert hostname " << hostname LOG(logERROR) << "Could not convert hostname " << hostname
<< " to internet address (zmq): " << " to internet address (zmq): "
"gettaddrinfo returned null"; "gettaddrinfo returned null";
@ -138,7 +138,7 @@ int ZmqSocket::ConvertInternetAddresstoIpString(struct addrinfo *res, char *ip,
const int ipsize) { const int ipsize) {
if (inet_ntop(res->ai_family, if (inet_ntop(res->ai_family,
&((struct sockaddr_in *)res->ai_addr)->sin_addr, ip, &((struct sockaddr_in *)res->ai_addr)->sin_addr, ip,
ipsize) != NULL) { ipsize) != nullptr) {
freeaddrinfo(res); freeaddrinfo(res);
return 0; return 0;
} }
@ -436,7 +436,7 @@ void ZmqSocket::PrintError() {
// Nested class to do RAII handling of socket descriptors // Nested class to do RAII handling of socket descriptors
ZmqSocket::mySocketDescriptors::mySocketDescriptors() ZmqSocket::mySocketDescriptors::mySocketDescriptors()
: server(false), contextDescriptor(0), socketDescriptor(0){}; : server(false), contextDescriptor(nullptr), socketDescriptor(nullptr){};
ZmqSocket::mySocketDescriptors::~mySocketDescriptors() { ZmqSocket::mySocketDescriptors::~mySocketDescriptors() {
Disconnect(); Disconnect();
Close(); Close();
@ -448,13 +448,13 @@ void ZmqSocket::mySocketDescriptors::Disconnect() {
zmq_disconnect(socketDescriptor, serverAddress); zmq_disconnect(socketDescriptor, serverAddress);
}; };
void ZmqSocket::mySocketDescriptors::Close() { void ZmqSocket::mySocketDescriptors::Close() {
if (socketDescriptor != NULL) { if (socketDescriptor != nullptr) {
zmq_close(socketDescriptor); zmq_close(socketDescriptor);
socketDescriptor = NULL; socketDescriptor = nullptr;
} }
if (contextDescriptor != NULL) { if (contextDescriptor != nullptr) {
zmq_ctx_destroy(contextDescriptor); zmq_ctx_destroy(contextDescriptor);
contextDescriptor = NULL; contextDescriptor = nullptr;
} }
}; };