Skip to content

Commit a600a70

Browse files
Replace NULLs with nullptr (#1544)
* nullptr fixes from clang-tidy * fix some clang-tidy warnings + typo * get rid of all NULLs * remove unnecessary change * fix comments * Fix comments * fix format * fix comments --------- Co-authored-by: Liu, An-Chi <[email protected]>
1 parent 37d95e2 commit a600a70

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+615
-617
lines changed

Common++/header/GeneralUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace pcpp
4747
* @param[in] haystackLen Length of the haystack buffer
4848
* @param[in] needle A pointer to a buffer that will be searched for
4949
* @param[in] needleLen Length of the needle buffer
50-
* @return A pointer to the beginning of the substring, or NULL if the substring is not found
50+
* @return A pointer to the beginning of the substring, or nullptr if the substring is not found
5151
*/
5252
char* cross_platform_memmem(const char* haystack, size_t haystackLen, const char* needle, size_t needleLen);
5353

Common++/header/IpUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @param[in] src Network address structure, can be either in_addr (IPv4) or in6_addr (IPv6)
3232
* @param[out] dst Network address string representation
3333
* @param[in] size 'dst' Maximum size
34-
* @return pointer to presentation format address ('dst'), or NULL (see errno).
34+
* @return pointer to presentation format address ('dst'), or nullptr (see errno).
3535
*/
3636
const char* inet_ntop(int af, const void* src, char* dst, size_t size);
3737

Common++/header/LRUList.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ namespace pcpp
4444
* this method will remove the least recently used element and return a value in deletedValue. Method complexity
4545
* is O(log(getSize())). This is a optimized version of the method T* put(const T&).
4646
* @param[in] element The element to insert or to advance to the head of the list (if already exists)
47-
* @param[out] deletedValue The value of deleted element if a pointer is not NULL. This parameter is optional.
47+
* @param[out] deletedValue The value of deleted element if a pointer is not nullptr. This parameter is
48+
* optional.
4849
* @return 0 if the list didn't reach its max size, 1 otherwise. In case the list already reached its max size
49-
* and deletedValue is not NULL the value of deleted element is copied into the place the deletedValue points
50+
* and deletedValue is not nullptr the value of deleted element is copied into the place the deletedValue points
5051
* to.
5152
*/
52-
int put(const T& element, T* deletedValue = NULL)
53+
int put(const T& element, T* deletedValue = nullptr)
5354
{
5455
m_CacheItemsList.push_front(element);
5556

@@ -68,7 +69,7 @@ namespace pcpp
6869
ListIterator lruIter = m_CacheItemsList.end();
6970
--lruIter;
7071

71-
if (deletedValue != NULL)
72+
if (deletedValue != nullptr)
7273
#if __cplusplus > 199711L || _MSC_VER >= 1800
7374
*deletedValue = std::move(*lruIter);
7475
#else

Common++/src/IpUtils.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static const char* inet_ntop4(const uint8_t* src, char* dst, size_t size)
138138
/* Note: nprinted *excludes* the trailing '\0' character */
139139
if ((size_t)nprinted >= size)
140140
{
141-
return (NULL);
141+
return (nullptr);
142142
}
143143
strncpy(dst, tmp, size);
144144
return (dst);
@@ -226,7 +226,7 @@ static const char* inet_ntop6(const uint8_t* src, char* dst, size_t size)
226226
if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
227227
{
228228
if (!inet_ntop4(src + 12, tp, sizeof tmp - (tp - tmp)))
229-
return (NULL);
229+
return (nullptr);
230230
tp += strlen(tp);
231231
break;
232232
}
@@ -242,7 +242,7 @@ static const char* inet_ntop6(const uint8_t* src, char* dst, size_t size)
242242
*/
243243
if ((size_t)(tp - tmp) > size)
244244
{
245-
return (NULL);
245+
return (nullptr);
246246
}
247247
strncpy(dst, tmp, size);
248248
return (dst);
@@ -271,7 +271,7 @@ static int inet_pton4(const char* src, uint8_t* dst)
271271
{
272272
const char* pch;
273273

274-
if ((pch = strchr(digits, ch)) != NULL)
274+
if ((pch = strchr(digits, ch)) != nullptr)
275275
{
276276
size_t newSize = *tp * 10 + (pch - digits);
277277

@@ -324,7 +324,7 @@ static int inet_pton6(const char* src, uint8_t* dst)
324324

325325
memset((tp = tmp), '\0', NS_IN6ADDRSZ);
326326
endp = tp + NS_IN6ADDRSZ;
327-
colonp = NULL;
327+
colonp = nullptr;
328328
/* Leading :: requires some special handling. */
329329
if (*src == ':')
330330
if (*++src != ':')
@@ -336,9 +336,9 @@ static int inet_pton6(const char* src, uint8_t* dst)
336336
{
337337
const char *pch, *xdigits;
338338

339-
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
339+
if ((pch = strchr((xdigits = xdigits_l), ch)) == nullptr)
340340
pch = strchr((xdigits = xdigits_u), ch);
341-
if (pch != NULL)
341+
if (pch != nullptr)
342342
{
343343
val <<= 4;
344344
val |= (pch - xdigits);
@@ -384,7 +384,7 @@ static int inet_pton6(const char* src, uint8_t* dst)
384384
*tp++ = (u_char)(val >> 8) & 0xff;
385385
*tp++ = (u_char)val & 0xff;
386386
}
387-
if (colonp != NULL)
387+
if (colonp != nullptr)
388388
{
389389
/*
390390
* Since some memmove()'s erroneously fail to handle
@@ -417,7 +417,7 @@ const char* inet_ntop(int af, const void* src, char* dst, size_t size)
417417
case AF_INET6:
418418
return (inet_ntop6((const uint8_t*)src, dst, size));
419419
default:
420-
return (NULL);
420+
return (nullptr);
421421
}
422422
/* NOTREACHED */
423423
}

Common++/src/SystemUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ namespace pcpp
319319
case CTRL_C_EVENT:
320320
case CTRL_BREAK_EVENT:
321321
{
322-
if (ApplicationEventHandler::getInstance().m_ApplicationInterruptedHandler != NULL)
322+
if (ApplicationEventHandler::getInstance().m_ApplicationInterruptedHandler != nullptr)
323323
ApplicationEventHandler::getInstance().m_ApplicationInterruptedHandler(
324324
ApplicationEventHandler::getInstance().m_ApplicationInterruptedCookie);
325325
return TRUE;
@@ -341,7 +341,7 @@ namespace pcpp
341341
{
342342
// Most calls are unsafe in a signal handler, and this includes printf(). In particular,
343343
// if the signal is caught while inside printf() it may be called twice at the same time which might not be
344-
// a good idea The way to make sure the signal is called only once is using this lock and putting NULL in
344+
// a good idea The way to make sure the signal is called only once is using this lock and putting nullptr in
345345
// m_ApplicationInterruptedHandler
346346
const std::lock_guard<std::mutex> lock(UnixLinuxHandlerRoutineMutex);
347347

Examples/DpdkBridge/AppWorkerThread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread
6666
// free packet array (frees all mbufs as well)
6767
for (int i = 0; i < MAX_RECEIVE_BURST; i++)
6868
{
69-
if (packetArr[i] != NULL)
69+
if (packetArr[i] != nullptr)
7070
delete packetArr[i];
7171
}
7272

Examples/DpdkBridge/Common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ struct AppWorkerConfig
4444
uint16_t RxQueues;
4545
pcpp::DpdkDevice* TxDevice;
4646

47-
AppWorkerConfig() : CoreId(MAX_NUM_OF_CORES + 1), RxDevice(NULL), RxQueues(1), TxDevice(NULL)
47+
AppWorkerConfig() : CoreId(MAX_NUM_OF_CORES + 1), RxDevice(nullptr), RxQueues(1), TxDevice(nullptr)
4848
{}
4949
};

Examples/DpdkBridge/main.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@
4747

4848
// clang-format off
4949
static struct option DpdkBridgeOptions[] = {
50-
{ "dpdk-ports", required_argument, 0, 'd' },
51-
{ "core-mask", optional_argument, 0, 'c' },
52-
{ "mbuf-pool-size", optional_argument, 0, 'm' },
53-
{ "queue-quantity", optional_argument, 0, 'q' },
54-
{ "help", optional_argument, 0, 'h' },
55-
{ "list", optional_argument, 0, 'l' },
56-
{ "version", optional_argument, 0, 'v' },
57-
{ 0, 0, 0, 0 }
50+
{ "dpdk-ports", required_argument, nullptr, 'd' },
51+
{ "core-mask", optional_argument, nullptr, 'c' },
52+
{ "mbuf-pool-size", optional_argument, nullptr, 'm' },
53+
{ "queue-quantity", optional_argument, nullptr, 'q' },
54+
{ "help", optional_argument, nullptr, 'h' },
55+
{ "list", optional_argument, nullptr, 'l' },
56+
{ "version", optional_argument, nullptr, 'v' },
57+
{ nullptr, 0, nullptr, 0 }
5858
};
5959
// clang-format on
6060

@@ -137,7 +137,7 @@ struct DpdkBridgeArgs
137137
bool shouldStop;
138138
std::vector<pcpp::DpdkWorkerThread*>* workerThreadsVector;
139139

140-
DpdkBridgeArgs() : shouldStop(false), workerThreadsVector(NULL)
140+
DpdkBridgeArgs() : shouldStop(false), workerThreadsVector(nullptr)
141141
{}
142142
};
143143

@@ -321,7 +321,7 @@ int main(int argc, char* argv[])
321321
for (const auto& port : dpdkPortVec)
322322
{
323323
pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(port);
324-
if (dev == NULL)
324+
if (dev == nullptr)
325325
{
326326
EXIT_WITH_ERROR("DPDK device for port " << port << " doesn't exist");
327327
}

Examples/DpdkExample-FilterTraffic/AppWorkerThread.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread
4848
m_Stop = false;
4949
m_Stats.workerId = coreId;
5050
pcpp::DpdkDevice* sendPacketsTo = m_WorkerConfig.sendPacketsTo;
51-
pcpp::PcapFileWriterDevice* pcapWriter = NULL;
51+
pcpp::PcapFileWriterDevice* pcapWriter = nullptr;
5252

5353
// if needed, create the pcap file writer which all matched packets will be written into
5454
if (m_WorkerConfig.writeMatchedPacketsToFile)
@@ -127,13 +127,13 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread
127127
if (packetMatched)
128128
{
129129
// send packet to TX port if needed
130-
if (sendPacketsTo != NULL)
130+
if (sendPacketsTo != nullptr)
131131
{
132132
sendPacketsTo->sendPacket(*packetArr[i], 0);
133133
}
134134

135135
// save packet to file if needed
136-
if (pcapWriter != NULL)
136+
if (pcapWriter != nullptr)
137137
{
138138
pcapWriter->writePacket(*packetArr[i]);
139139
}
@@ -148,12 +148,12 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread
148148
// free packet array (frees all mbufs as well)
149149
for (int i = 0; i < MAX_RECEIVE_BURST; i++)
150150
{
151-
if (packetArr[i] != NULL)
151+
if (packetArr[i] != nullptr)
152152
delete packetArr[i];
153153
}
154154

155155
// close and delete pcap file writer
156-
if (pcapWriter != NULL)
156+
if (pcapWriter != nullptr)
157157
{
158158
delete pcapWriter;
159159
}

Examples/DpdkExample-FilterTraffic/main.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@
4444

4545
// clang-format off
4646
static struct option FilterTrafficOptions[] = {
47-
{ "dpdk-ports", required_argument, 0, 'd' },
48-
{ "send-matched-packets", optional_argument, 0, 's' },
49-
{ "save-matched-packets", optional_argument, 0, 'f' },
50-
{ "match-source-ip", optional_argument, 0, 'i' },
51-
{ "match-dest-ip", optional_argument, 0, 'I' },
52-
{ "match-source-port", optional_argument, 0, 'p' },
53-
{ "match-dest-port", optional_argument, 0, 'P' },
54-
{ "match-protocol", optional_argument, 0, 'o' },
55-
{ "core-mask", optional_argument, 0, 'c' },
56-
{ "mbuf-pool-size", optional_argument, 0, 'm' },
57-
{ "rx-queues", optional_argument, 0, 'r' },
58-
{ "tx-queues", optional_argument, 0, 't' },
59-
{ "help", optional_argument, 0, 'h' },
60-
{ "version", optional_argument, 0, 'v' },
61-
{ "list", optional_argument, 0, 'l' },
62-
{ 0, 0, 0, 0 }
47+
{ "dpdk-ports", required_argument, nullptr, 'd' },
48+
{ "send-matched-packets", optional_argument, nullptr, 's' },
49+
{ "save-matched-packets", optional_argument, nullptr, 'f' },
50+
{ "match-source-ip", optional_argument, nullptr, 'i' },
51+
{ "match-dest-ip", optional_argument, nullptr, 'I' },
52+
{ "match-source-port", optional_argument, nullptr, 'p' },
53+
{ "match-dest-port", optional_argument, nullptr, 'P' },
54+
{ "match-protocol", optional_argument, nullptr, 'o' },
55+
{ "core-mask", optional_argument, nullptr, 'c' },
56+
{ "mbuf-pool-size", optional_argument, nullptr, 'm' },
57+
{ "rx-queues", optional_argument, nullptr, 'r' },
58+
{ "tx-queues", optional_argument, nullptr, 't' },
59+
{ "help", optional_argument, nullptr, 'h' },
60+
{ "version", optional_argument, nullptr, 'v' },
61+
{ "list", optional_argument, nullptr, 'l' },
62+
{ nullptr, 0, nullptr, 0 }
6363
};
6464
// clang-format on
6565

@@ -235,7 +235,7 @@ struct FilterTrafficArgs
235235
bool shouldStop;
236236
std::vector<pcpp::DpdkWorkerThread*>* workerThreadsVector;
237237

238-
FilterTrafficArgs() : shouldStop(false), workerThreadsVector(NULL)
238+
FilterTrafficArgs() : shouldStop(false), workerThreadsVector(nullptr)
239239
{}
240240
};
241241

@@ -545,7 +545,7 @@ int main(int argc, char* argv[])
545545
for (const auto& port : dpdkPortVec)
546546
{
547547
pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(port);
548-
if (dev == NULL)
548+
if (dev == nullptr)
549549
{
550550
EXIT_WITH_ERROR("DPDK device for port " << port << " doesn't exist");
551551
}
@@ -581,9 +581,9 @@ int main(int argc, char* argv[])
581581
}
582582
}
583583

584-
// get DPDK device to send packets to (or NULL if doesn't exist)
584+
// get DPDK device to send packets to (or nullptr if doesn't exist)
585585
pcpp::DpdkDevice* sendPacketsTo = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(sendPacketsToPort);
586-
if (sendPacketsTo != NULL && !sendPacketsTo->isOpened() && !sendPacketsTo->open())
586+
if (sendPacketsTo != nullptr && !sendPacketsTo->isOpened() && !sendPacketsTo->open())
587587
{
588588
EXIT_WITH_ERROR("Could not open port#" << sendPacketsToPort << " for sending matched packets");
589589
}

0 commit comments

Comments
 (0)