Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang format for Common++ #1451

Merged
merged 15 commits into from
Jun 21, 2024
Prev Previous commit
Next Next commit
rerun the clang-format
  • Loading branch information
tigercosmos committed Jun 19, 2024
commit 2bb033a1d749d0ad1aea5ea36cbbf9195b99968b
2 changes: 1 addition & 1 deletion Common++/header/DeprecationUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# define DISABLE_WARNING(warningName) DO_PRAGMA(GCC diagnostic ignored #warningName)

// clang-format off
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is the manual fix, since the clang-formant cannot do the formating well here. it tries to separate -Wdeprecated-declarations to -Wdeprecated - declarations

#define DISABLE_WARNING_DEPRECATED DISABLE_WARNING(-Wdeprecated-declarations)
# define DISABLE_WARNING_DEPRECATED DISABLE_WARNING(-Wdeprecated-declarations)
// clang-format on
# else
# pragma message("WARNING: Disabling of warnings is not implemented for this compiler")
Expand Down
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 <stdint.h>
#include <string>
#include <stdint.h>
#include <type_traits>

/// @file
Expand Down
18 changes: 9 additions & 9 deletions Common++/header/IpAddress.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once

#include <algorithm>
#include <array>
#include <memory>
#include <ostream>
#include <stdint.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <ostream>
#include <array>
#include <memory>

/// @file

Expand Down Expand Up @@ -123,7 +123,7 @@ namespace pcpp

uint32_t rhsIntVal = rhs.toInt();
std::reverse(reinterpret_cast<uint8_t*>(&rhsIntVal),
reinterpret_cast<uint8_t*>(&rhsIntVal) + sizeof(rhsIntVal));
reinterpret_cast<uint8_t*>(&rhsIntVal) + sizeof(rhsIntVal));

return intVal < rhsIntVal;
}
Expand Down Expand Up @@ -975,7 +975,7 @@ namespace pcpp
IPAddress getNetworkPrefix() const
{
return (m_IPv4Network != nullptr ? IPAddress(m_IPv4Network->getNetworkPrefix())
: IPAddress(m_IPv6Network->getNetworkPrefix()));
: IPAddress(m_IPv6Network->getNetworkPrefix()));
}

/**
Expand All @@ -985,7 +985,7 @@ namespace pcpp
IPAddress getLowestAddress() const
{
return (m_IPv4Network != nullptr ? IPAddress(m_IPv4Network->getLowestAddress())
: IPAddress(m_IPv6Network->getLowestAddress()));
: IPAddress(m_IPv6Network->getLowestAddress()));
}

/**
Expand All @@ -995,7 +995,7 @@ namespace pcpp
IPAddress getHighestAddress() const
{
return (m_IPv4Network != nullptr ? IPAddress(m_IPv4Network->getHighestAddress())
: IPAddress(m_IPv6Network->getHighestAddress()));
: IPAddress(m_IPv6Network->getHighestAddress()));
}

/**
Expand All @@ -1006,7 +1006,7 @@ namespace pcpp
uint64_t getTotalAddressCount() const
{
return (m_IPv4Network != nullptr ? m_IPv4Network->getTotalAddressCount()
: m_IPv6Network->getTotalAddressCount());
: m_IPv6Network->getTotalAddressCount());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions Common++/header/IpUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

#include <stdint.h>
#ifdef __linux__
# include <arpa/inet.h>
# include <netinet/in.h>
# include <arpa/inet.h>
#endif
#if defined(__APPLE__)
# include <arpa/inet.h>
# include <netinet/in.h>
# include <arpa/inet.h>
#endif
#if defined(_WIN32)
# include <ws2tcpip.h>
#endif
#if defined(__FreeBSD__)
# include <arpa/inet.h>
# include <netinet/in.h>
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h>
#endif

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

#include <list>
#include <unordered_map>
#include <list>

#if __cplusplus > 199711L || _MSC_VER >= 1800
# include <utility>
Expand Down Expand Up @@ -56,7 +56,7 @@ namespace pcpp
// Inserting a new element. If an element with an equivalent key already exists the method returns an
// iterator to the element that prevented the insertion
std::pair<MapIterator, bool> pair =
m_CacheItemsMap.insert(std::make_pair(element, m_CacheItemsList.begin()));
m_CacheItemsMap.insert(std::make_pair(element, m_CacheItemsList.begin()));
if (pair.second == false) // already exists
{
m_CacheItemsList.erase(pair.first->second);
Expand Down
4 changes: 2 additions & 2 deletions Common++/header/Logger.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

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

#ifndef LOG_MODULE
# define LOG_MODULE UndefinedLogModule
Expand Down
10 changes: 5 additions & 5 deletions Common++/header/MacAddress.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once

#include <algorithm>
#include <initializer_list>
#include <iterator>
#include <ostream>
#include <stdint.h>
#include <string.h>
#include <string>
#include <initializer_list>
#include <algorithm>
#include <iterator>
#include <ostream>

/// @file

Expand Down Expand Up @@ -66,7 +66,7 @@ namespace pcpp
* @param[in] sixthOctet Represent the sixth octet in the address
*/
inline MacAddress(uint8_t firstOctet, uint8_t secondOctet, uint8_t thirdOctet, uint8_t fourthOctet,
uint8_t fifthOctet, uint8_t sixthOctet)
uint8_t fifthOctet, uint8_t sixthOctet)
{
m_Address[0] = firstOctet;
m_Address[1] = secondOctet;
Expand Down
2 changes: 1 addition & 1 deletion Common++/header/PointerVector.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <stdint.h>
#include <stdio.h>
#include <stdint.h>
#include <vector>

/// @file
Expand Down
6 changes: 3 additions & 3 deletions Common++/src/IpAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace pcpp
bool IPv4Address::isMulticast() const
{
return !operator<(MulticastRangeLowerBound) &&
(operator<(MulticastRangeUpperBound) || operator==(MulticastRangeUpperBound));
(operator<(MulticastRangeUpperBound) || operator==(MulticastRangeUpperBound));
}

IPv4Address::IPv4Address(const std::string& addrAsString)
Expand Down Expand Up @@ -237,7 +237,7 @@ namespace pcpp
if (netmaskStr.empty())
{
throw std::invalid_argument(
"The input should be in the format of <address>/<netmask> or <address>/<prefixLength>");
"The input should be in the format of <address>/<netmask> or <address>/<prefixLength>");
}

IPv4Address networkPrefix;
Expand Down Expand Up @@ -443,7 +443,7 @@ namespace pcpp
if (netmaskStr.empty())
{
throw std::invalid_argument(
"The input should be in the format of <address>/<netmask> or <address>/<prefixLength>");
"The input should be in the format of <address>/<netmask> or <address>/<prefixLength>");
}

IPv6Address networkPrefix;
Expand Down
4 changes: 2 additions & 2 deletions Common++/src/IpUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace pcpp
throw std::invalid_argument("Insufficient buffer");

if (inet_ntop(AF_INET, &(reinterpret_cast<sockaddr_in const*>(sa)->sin_addr), resultString,
resultBufLen) == nullptr)
resultBufLen) == nullptr)
{
throw std::runtime_error("Unknown error during conversion");
}
Expand All @@ -94,7 +94,7 @@ namespace pcpp
throw std::invalid_argument("Insufficient buffer");

if (inet_ntop(AF_INET6, &(reinterpret_cast<sockaddr_in6 const*>(sa)->sin6_addr), resultString,
resultBufLen) == nullptr)
resultBufLen) == nullptr)
{
throw std::runtime_error("Unknown error during conversion");
}
Expand Down
8 changes: 4 additions & 4 deletions Common++/src/Logger.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Logger.h"
#include <sstream>
#include "Logger.h"

namespace pcpp
{
Expand All @@ -25,12 +25,12 @@ namespace pcpp
}

void Logger::defaultLogPrinter(LogLevel logLevel, const std::string& logMessage, const std::string& file,
const std::string& method, const int line)
const std::string& method, const int line)
{
std::ostringstream sstream;
sstream << file << ": " << method << ":" << line;
std::cout << std::left << "[" << std::setw(5) << Logger::logLevelAsString(logLevel) << ": " << std::setw(45)
<< sstream.str() << "] " << logMessage << std::endl;
<< sstream.str() << "] " << logMessage << std::endl;
}

std::ostringstream* Logger::internalCreateLogStream()
Expand All @@ -39,7 +39,7 @@ namespace pcpp
}

void Logger::internalPrintLogMessage(std::ostringstream* logStream, Logger::LogLevel logLevel, const char* file,
const char* method, int line)
const char* method, int line)
{
std::string logMessage = logStream->str();
delete logStream;
Expand Down
6 changes: 3 additions & 3 deletions Common++/src/MacAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace pcpp
{
char str[19];
snprintf(str, sizeof str, "%02x:%02x:%02x:%02x:%02x:%02x", m_Address[0], m_Address[1], m_Address[2],
m_Address[3], m_Address[4], m_Address[5]);
m_Address[3], m_Address[4], m_Address[5]);
return std::string(str);
}

Expand All @@ -20,8 +20,8 @@ namespace pcpp
constexpr size_t validMacAddressLength = 17;
unsigned int values[6];
if (address.size() != validMacAddressLength ||
sscanf(address.c_str(), "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4],
&values[5]) != 6)
sscanf(address.c_str(), "%x:%x:%x:%x:%x:%x", &values[0], &values[1], &values[2], &values[3], &values[4],
&values[5]) != 6)
{
throw std::invalid_argument("Invalid MAC address format, should be xx:xx:xx:xx:xx:xx");
}
Expand Down
10 changes: 5 additions & 5 deletions Common++/src/OUILookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace pcpp
continue;
auto subVal = entry.get<nlohmann::json>();
if (subVal.contains("mask") && subVal.contains("vendors") && subVal["mask"].is_number_integer() &&
subVal["vendors"].is_object())
subVal["vendors"].is_object())
{
int maskValue = subVal["mask"].get<int>();
vLocalMaskedFilter.push_back({maskValue, {}});
Expand All @@ -44,7 +44,7 @@ namespace pcpp
if (subentry.value().is_string())
{
vLocalMaskedFilter.back().vendorMap.insert(
{std::stoull(subentry.key()), subentry.value()});
{std::stoull(subentry.key()), subentry.value()});
++ctrRead;
}
}
Expand All @@ -53,7 +53,7 @@ namespace pcpp
}

vendorMap.insert({
std::stoull(line.key()), {val["vendor"], vLocalMaskedFilter}
std::stoull(line.key()), {val["vendor"], vLocalMaskedFilter}
});
++ctrRead;
}
Expand Down Expand Up @@ -88,8 +88,8 @@ namespace pcpp
addr.copyTo(buffArray);

uint64_t macAddr = (((uint64_t)((buffArray)[5]) << 0) + ((uint64_t)((buffArray)[4]) << 8) +
((uint64_t)((buffArray)[3]) << 16) + ((uint64_t)((buffArray)[2]) << 24) +
((uint64_t)((buffArray)[1]) << 32) + ((uint64_t)((buffArray)[0]) << 40));
((uint64_t)((buffArray)[3]) << 16) + ((uint64_t)((buffArray)[2]) << 24) +
((uint64_t)((buffArray)[1]) << 32) + ((uint64_t)((buffArray)[0]) << 40));

auto itr = vendorMap.find(macAddr >> 24);
if (itr == vendorMap.end())
Expand Down
26 changes: 13 additions & 13 deletions Common++/src/SystemUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#ifndef _MSC_VER
# include <unistd.h>
#endif
#include <stdexcept>
#include <memory>
#include <array>
#include <iostream>
#include <memory>
#include <mutex>
#include <signal.h>
#include <stdexcept>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -107,13 +107,13 @@ namespace pcpp
const SystemCore SystemCores::Core31 = {0x80000000, 31};

const SystemCore SystemCores::IdToSystemCore[MAX_NUM_OF_CORES] = {
SystemCores::Core0, SystemCores::Core1, SystemCores::Core2, SystemCores::Core3, SystemCores::Core4,
SystemCores::Core5, SystemCores::Core6, SystemCores::Core7, SystemCores::Core8, SystemCores::Core9,
SystemCores::Core10, SystemCores::Core11, SystemCores::Core12, SystemCores::Core13, SystemCores::Core14,
SystemCores::Core15, SystemCores::Core16, SystemCores::Core17, SystemCores::Core18, SystemCores::Core19,
SystemCores::Core20, SystemCores::Core21, SystemCores::Core22, SystemCores::Core23, SystemCores::Core24,
SystemCores::Core25, SystemCores::Core26, SystemCores::Core27, SystemCores::Core28, SystemCores::Core29,
SystemCores::Core30, SystemCores::Core31};
SystemCores::Core0, SystemCores::Core1, SystemCores::Core2, SystemCores::Core3, SystemCores::Core4,
SystemCores::Core5, SystemCores::Core6, SystemCores::Core7, SystemCores::Core8, SystemCores::Core9,
SystemCores::Core10, SystemCores::Core11, SystemCores::Core12, SystemCores::Core13, SystemCores::Core14,
SystemCores::Core15, SystemCores::Core16, SystemCores::Core17, SystemCores::Core18, SystemCores::Core19,
SystemCores::Core20, SystemCores::Core21, SystemCores::Core22, SystemCores::Core23, SystemCores::Core24,
SystemCores::Core25, SystemCores::Core26, SystemCores::Core27, SystemCores::Core28, SystemCores::Core29,
SystemCores::Core30, SystemCores::Core31};

int getNumOfCores()
{
Expand Down Expand Up @@ -238,7 +238,7 @@ namespace pcpp

sec = count.QuadPart / clock_gettime_counts_per_sec.QuadPart;
nsec = ((count.QuadPart % clock_gettime_counts_per_sec.QuadPart) * CLOCK_GETTIME_BILLION) /
clock_gettime_counts_per_sec.QuadPart;
clock_gettime_counts_per_sec.QuadPart;

return 0;

Expand Down Expand Up @@ -320,7 +320,7 @@ namespace pcpp
{
if (ApplicationEventHandler::getInstance().m_ApplicationInterruptedHandler != NULL)
ApplicationEventHandler::getInstance().m_ApplicationInterruptedHandler(
ApplicationEventHandler::getInstance().m_ApplicationInterruptedCookie);
ApplicationEventHandler::getInstance().m_ApplicationInterruptedCookie);
return TRUE;
}

Expand All @@ -346,7 +346,7 @@ namespace pcpp

if (ApplicationEventHandler::getInstance().m_ApplicationInterruptedHandler != nullptr)
ApplicationEventHandler::getInstance().m_ApplicationInterruptedHandler(
ApplicationEventHandler::getInstance().m_ApplicationInterruptedCookie);
ApplicationEventHandler::getInstance().m_ApplicationInterruptedCookie);

ApplicationEventHandler::getInstance().m_ApplicationInterruptedHandler = nullptr;

Expand All @@ -361,7 +361,7 @@ namespace pcpp
#endif

ApplicationEventHandler::ApplicationEventHandler()
: m_ApplicationInterruptedHandler(nullptr), m_ApplicationInterruptedCookie(nullptr)
: m_ApplicationInterruptedHandler(nullptr), m_ApplicationInterruptedCookie(nullptr)
{
}

Expand Down
6 changes: 3 additions & 3 deletions Common++/src/TablePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace pcpp
{

TablePrinter::TablePrinter(std::vector<std::string> columnNames, std::vector<int> columnWidths)
: m_ColumnNames(std::move(columnNames)), m_ColumnWidths(std::move(columnWidths)), m_FirstRow(true),
m_TableClosed(false)
: m_ColumnNames(std::move(columnNames)), m_ColumnWidths(std::move(columnWidths)), m_FirstRow(true),
m_TableClosed(false)
{
if (m_ColumnWidths.size() != m_ColumnNames.size())
{
PCPP_LOG_ERROR("Cannot create table: number of column names provided is different than number of column "
"widths provided");
"widths provided");
m_TableClosed = true;
}
}
Expand Down
Loading