Skip to content

Commit

Permalink
clang-tidy auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
egecetin committed Nov 7, 2024
1 parent 7f191ee commit 559ae1d
Show file tree
Hide file tree
Showing 238 changed files with 7,865 additions and 5,041 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ BreakBeforeBraces: Custom
BraceWrapping:
SplitEmptyFunction: false
AfterCaseLabel: true
QualifierAlignment: Left
...
17 changes: 17 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Checks: 'cert-*,
clang-analyzer-*,
concurrency-*,
cppcoreguidelines-*,
misc-*,
modernize-*,
performance-*,
portability-*,
readability-*,
-clang-diagnostic-unused-command-line-argument,
-cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-vararg,
-modernize-use-trailing-return-type,
-misc-include-cleaner'
2 changes: 1 addition & 1 deletion Common++/header/GeneralUtils.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <string>
#include <stdint.h>
#include <cstdint>
#include <type_traits>

/// @file
Expand Down
58 changes: 27 additions & 31 deletions Common++/header/IpAddress.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <stdint.h>
#include <string.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <algorithm>
#include <ostream>
Expand Down Expand Up @@ -186,7 +186,7 @@ namespace pcpp

uint32_t IPv4Address::toInt() const
{
uint32_t addr;
uint32_t addr = 0;
memcpy(&addr, m_Bytes.data(), m_Bytes.size() * sizeof(uint8_t));
return addr;
}
Expand Down Expand Up @@ -518,7 +518,9 @@ namespace pcpp
bool IPAddress::operator==(const IPAddress& rhs) const
{
if (isIPv4())
{
return rhs.isIPv4() ? (m_IPv4 == rhs.m_IPv4) : false;
}

return rhs.isIPv6() ? m_IPv6 == rhs.m_IPv6 : false;
}
Expand Down Expand Up @@ -561,7 +563,7 @@ namespace pcpp
*
* @param address An address representing the network prefix.
*/
explicit IPv4Network(const IPv4Address& address) : IPv4Network(address, 32u)
explicit IPv4Network(const IPv4Address& address) : IPv4Network(address, 32U)
{}

/**
Expand Down Expand Up @@ -657,10 +659,10 @@ namespace pcpp
std::string toString() const;

private:
uint32_t m_NetworkPrefix;
uint32_t m_Mask;
uint32_t m_NetworkPrefix{};
uint32_t m_Mask{};

bool isValidNetmask(const IPv4Address& netmaskAddress);
static bool isValidNetmask(const IPv4Address& netmaskAddress);
void initFromAddressAndPrefixLength(const IPv4Address& address, uint8_t prefixLen);
void initFromAddressAndNetmask(const IPv4Address& address, const IPv4Address& netmaskAddress);
};
Expand All @@ -678,7 +680,7 @@ namespace pcpp
*
* @param address An address representing the network prefix.
*/
explicit IPv6Network(const IPv6Address& address) : IPv6Network(address, 128u)
explicit IPv6Network(const IPv6Address& address) : IPv6Network(address, 128U)
{}

/**
Expand Down Expand Up @@ -733,7 +735,7 @@ namespace pcpp
*/
IPv6Address getNetworkPrefix() const
{
return IPv6Address(m_NetworkPrefix);
return { m_NetworkPrefix };
}

/**
Expand Down Expand Up @@ -774,10 +776,10 @@ namespace pcpp
std::string toString() const;

private:
uint8_t m_NetworkPrefix[16];
uint8_t m_Mask[16];
uint8_t m_NetworkPrefix[16]{};
uint8_t m_Mask[16]{};

bool isValidNetmask(const IPv6Address& netmaskAddress);
static bool isValidNetmask(const IPv6Address& netmaskAddress);
void initFromAddressAndPrefixLength(const IPv6Address& address, uint8_t prefixLen);
void initFromAddressAndNetmask(const IPv6Address& address, const IPv6Address& netmaskAddress);
};
Expand All @@ -795,7 +797,7 @@ namespace pcpp
*
* @param address An address representing the network prefix.
*/
explicit IPNetwork(const IPAddress& address) : IPNetwork(address, address.isIPv4() ? 32u : 128u)
explicit IPNetwork(const IPAddress& address) : IPNetwork(address, address.isIPv4() ? 32U : 128U)
{}

/**
Expand Down Expand Up @@ -892,10 +894,8 @@ namespace pcpp
{
return this->operator=(*other.m_IPv4Network);
}
else
{
return this->operator=(*other.m_IPv6Network);
}

return this->operator=(*other.m_IPv6Network);
}

/**
Expand Down Expand Up @@ -1032,15 +1032,13 @@ namespace pcpp

return m_IPv4Network->includes(address.getIPv4());
}
else
{
if (address.isIPv4())
{
return false;
}

return m_IPv6Network->includes(address.getIPv6());
if (address.isIPv4())
{
return false;
}

return m_IPv6Network->includes(address.getIPv6());
}

/**
Expand All @@ -1058,15 +1056,13 @@ namespace pcpp

return m_IPv4Network->includes(*network.m_IPv4Network);
}
else
{
if (network.isIPv4Network())
{
return false;
}

return m_IPv6Network->includes(*network.m_IPv6Network);
if (network.isIPv4Network())
{
return false;
}

return m_IPv6Network->includes(*network.m_IPv6Network);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Common++/header/IpUtils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <stdint.h>
#include <cstdint>
#ifdef __linux__
# include <netinet/in.h>
# include <arpa/inet.h>
Expand Down Expand Up @@ -95,7 +95,7 @@ namespace pcpp
* @throws std::invalid_argument Sockaddr family is not AF_INET or AF_INET6, sockaddr is nullptr or the result
* str buffer is insufficient.
*/
void sockaddr2string(sockaddr const* sa, char* resultString, size_t resultBufLen);
void sockaddr2string(const sockaddr* sa, char* resultString, size_t resultBufLen);

/**
* Convert a in_addr format address to 32bit representation
Expand Down
16 changes: 9 additions & 7 deletions Common++/header/LRUList.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ namespace pcpp
template <typename T> class LRUList
{
public:
typedef typename std::list<T>::iterator ListIterator;
typedef typename std::unordered_map<T, ListIterator>::iterator MapIterator;
using ListIterator = typename std::list<T>::iterator;
using MapIterator = typename std::unordered_map<T, ListIterator>::iterator;

/**
* A c'tor for this class
* @param[in] maxSize The max size this list can go
*/
explicit LRUList(size_t maxSize)
{
m_MaxSize = maxSize;
}
explicit LRUList(size_t maxSize) : m_MaxSize(maxSize)
{}

/**
* Puts an element in the list. This element will be inserted (or advanced if it already exists) to the head of
Expand All @@ -59,7 +57,7 @@ namespace pcpp
// iterator to the element that prevented the insertion
std::pair<MapIterator, bool> pair =
m_CacheItemsMap.insert(std::make_pair(element, m_CacheItemsList.begin()));
if (pair.second == false) // already exists
if (!static_cast<bool>(pair.second)) // already exists
{
m_CacheItemsList.erase(pair.first->second);
pair.first->second = m_CacheItemsList.begin();
Expand All @@ -71,8 +69,10 @@ namespace pcpp
--lruIter;

if (deletedValue != nullptr)
{
#if __cplusplus > 199711L || _MSC_VER >= 1800
*deletedValue = std::move(*lruIter);
}
#else
*deletedValue = *lruIter;
#endif
Expand Down Expand Up @@ -110,7 +110,9 @@ namespace pcpp
{
MapIterator iter = m_CacheItemsMap.find(element);
if (iter == m_CacheItemsMap.end())
{
return;
}

m_CacheItemsList.erase(iter->second);
m_CacheItemsMap.erase(iter);
Expand Down
17 changes: 9 additions & 8 deletions Common++/header/Logger.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdint.h>
#include <cstdint>

#ifndef LOG_MODULE
# define LOG_MODULE UndefinedLogModule
Expand Down Expand Up @@ -159,8 +159,7 @@ namespace pcpp
* @param[in] method The method in PcapPlusPlus code the log message is coming from
* @param[in] line The line in PcapPlusPlus code the log message is coming from
*/
typedef void (*LogPrinter)(LogLevel logLevel, const std::string& logMessage, const std::string& file,
const std::string& method, const int line);
using LogPrinter = void (*)(LogLevel, const std::string&, const std::string&, const std::string&, const int);

/**
* A static method for converting the log level enum to a string.
Expand Down Expand Up @@ -206,7 +205,9 @@ namespace pcpp
void setAllModulesToLogLevel(LogLevel level)
{
for (int i = 1; i < NumOfLogModules; i++)
{
m_LogModulesArray[i] = level;
}
}

/**
Expand Down Expand Up @@ -265,7 +266,7 @@ namespace pcpp
return *this;
}

std::ostringstream* internalCreateLogStream();
static std::ostringstream* internalCreateLogStream();

/**
* An internal method to print log messages. Shouldn't be used externally.
Expand All @@ -286,15 +287,15 @@ namespace pcpp

private:
bool m_LogsEnabled;
Logger::LogLevel m_LogModulesArray[NumOfLogModules];
Logger::LogLevel m_LogModulesArray[NumOfLogModules]{};
LogPrinter m_LogPrinter;
std::string m_LastError;
std::ostringstream* m_LogStream;
std::ostringstream* m_LogStream{};

// private c'tor - this class is a singleton
Logger();

static void defaultLogPrinter(LogLevel logLevel, const std::string& logMessage, const std::string& file,
const std::string& method, const int line);
const std::string& method, int line);
};
} // namespace pcpp
4 changes: 2 additions & 2 deletions Common++/header/MacAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <initializer_list>
#include <iterator>
#include <ostream>
#include <stdint.h>
#include <string.h>
#include <cstdint>
#include <cstring>
#include <string>

/// @file
Expand Down
2 changes: 1 addition & 1 deletion Common++/header/OUILookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace pcpp
* MAC addresses with only first three octets. The first element is unsigned integer equivalent of "XX:XX:XX"
* formatted MAC address
*/
typedef std::unordered_map<uint64_t, VendorData> OUIVendorMap;
using OUIVendorMap = std::unordered_map<uint64_t, VendorData>;

/// Internal vendor list for MAC addresses
OUIVendorMap vendorMap;
Expand Down
17 changes: 8 additions & 9 deletions Common++/header/PointerVector.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <cstddef>
#include <stdio.h>
#include <stdint.h>
#include <cstdio>
#include <cstdint>
#include <stdexcept>
#include <vector>
#include <memory>
Expand Down Expand Up @@ -70,8 +70,7 @@ namespace pcpp
/**
* A constructor that create an empty instance of this object
*/
PointerVector()
{}
PointerVector() = default;

/**
* Copies the vector along with all elements inside it.
Expand Down Expand Up @@ -259,7 +258,7 @@ namespace pcpp
/**
* @return A pointer to the first element in the vector
*/
T const* front() const
const T* front() const
{
return m_Vector.front();
}
Expand All @@ -275,7 +274,7 @@ namespace pcpp
/*
* @return A pointer to the last element in the vector.
*/
T const* back() const
const T* back() const
{
return m_Vector.back();
}
Expand Down Expand Up @@ -336,7 +335,7 @@ namespace pcpp
* @param[in] position An iterator pointing to the element to detach.
* @return An unique pointer that holds ownership of the detached element.
*/
std::unique_ptr<T> getAndDetach(VectorIterator const& position)
std::unique_ptr<T> getAndDetach(const VectorIterator& position)
{
std::unique_ptr<T> result(*position);
m_Vector.erase(position);
Expand Down Expand Up @@ -369,7 +368,7 @@ namespace pcpp
* The caller is responsible of freeing the copied elements.
* @return A vector of pointers to the newly copied elements.
*/
static std::vector<T*> deepCopyUnsafe(std::vector<T*> const& origin)
static std::vector<T*> deepCopyUnsafe(const std::vector<T*>& origin)
{
std::vector<T*> copyVec;
// Allocate the vector initially to ensure no exceptions are thrown during push_back.
Expand Down Expand Up @@ -402,7 +401,7 @@ namespace pcpp
* @param[in] origin The vector of elements to free.
* @remarks The vector's contents are not cleared and will point to invalid locations in memory.
*/
static void freeVectorUnsafe(std::vector<T*> const& origin)
static void freeVectorUnsafe(const std::vector<T*>& origin)
{
for (auto& obj : origin)
{
Expand Down
Loading

0 comments on commit 559ae1d

Please sign in to comment.