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-tidy fixes for Common++ #1639

Open
wants to merge 21 commits into
base: dev
Choose a base branch
from
Open

Conversation

egecetin
Copy link
Collaborator

@egecetin egecetin commented Nov 7, 2024

Fix various clang-tidy warnings for Common++

Requires #1677

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 75.56818% with 43 lines in your changes missing coverage. Please review.

Project coverage is 83.11%. Comparing base (7898a5d) to head (a8779e0).

Files with missing lines Patch % Lines
Common++/src/Logger.cpp 16.66% 15 Missing ⚠️
Common++/src/SystemUtils.cpp 66.66% 7 Missing ⚠️
Common++/src/IpUtils.cpp 70.58% 3 Missing and 2 partials ⚠️
...ples/IcmpFileTransfer/IcmpFileTransfer-pitcher.cpp 0.00% 3 Missing ⚠️
Common++/src/IpAddress.cpp 93.54% 2 Missing ⚠️
Common++/src/OUILookup.cpp 77.77% 1 Missing and 1 partial ⚠️
Examples/ArpSpoofing/main.cpp 0.00% 2 Missing ⚠️
Common++/src/GeneralUtils.cpp 80.00% 1 Missing ⚠️
Common++/src/MacAddress.cpp 75.00% 0 Missing and 1 partial ⚠️
Examples/DnsSpoofing/main.cpp 0.00% 1 Missing ⚠️
... and 4 more
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1639      +/-   ##
==========================================
- Coverage   83.16%   83.11%   -0.05%     
==========================================
  Files         277      277              
  Lines       48201    48217      +16     
  Branches     9932     9957      +25     
==========================================
- Hits        40086    40077       -9     
+ Misses       7266     7264       -2     
- Partials      849      876      +27     
Flag Coverage Δ
alpine320 75.11% <73.91%> (-0.05%) ⬇️
fedora40 75.16% <75.00%> (-0.01%) ⬇️
macos-13 80.62% <72.95%> (-0.04%) ⬇️
macos-14 80.62% <72.95%> (-0.04%) ⬇️
macos-15 80.60% <71.71%> (-0.04%) ⬇️
mingw32 70.82% <72.97%> (-0.09%) ⬇️
mingw64 70.79% <72.97%> (-0.09%) ⬇️
npcap 85.25% <81.35%> (-0.07%) ⬇️
rhel94 74.99% <75.00%> (-0.04%) ⬇️
ubuntu2004 58.57% <73.88%> (-0.06%) ⬇️
ubuntu2004-zstd 58.69% <73.88%> (-0.04%) ⬇️
ubuntu2204 74.91% <74.45%> (-0.07%) ⬇️
ubuntu2204-icpx 61.46% <67.88%> (+0.01%) ⬆️
ubuntu2404 75.16% <74.63%> (-0.07%) ⬇️
unittest 83.11% <75.56%> (-0.05%) ⬇️
windows-2019 85.28% <81.35%> (-0.07%) ⬇️
windows-2022 85.31% <81.35%> (-0.07%) ⬇️
winpcap 85.27% <81.35%> (-0.06%) ⬇️
xdp 50.52% <25.54%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@seladb
Copy link
Owner

seladb commented Nov 8, 2024

@egecetin please see this comment: #1637 (comment)

@egecetin
Copy link
Collaborator Author

egecetin commented Nov 8, 2024

@seladb Actually it is related with #1638 not this one 🙂. This PR for fixing of issues pointed by clang-tidy

@seladb
Copy link
Owner

seladb commented Nov 8, 2024

@seladb Actually it is related with #1638 not this one 🙂. This PR for fixing of issues pointed by clang-tidy

Oops sorry, I commented on the wrong PR... 🤦‍♂️

@egecetin egecetin changed the title Clang-tidy fixes Clang-tidy fixes for Common++ Nov 9, 2024
.clang-format Outdated
@@ -21,4 +21,5 @@ BreakBeforeBraces: Custom
BraceWrapping:
SplitEmptyFunction: false
AfterCaseLabel: true
QualifierAlignment: Left
Copy link
Collaborator

Choose a reason for hiding this comment

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

RIP, const on the right... I found that easier to read because its consistent behavior with its usage in the middle...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let me check the codebase again. If most of them left it is better to split PR for changing it. Anyway, lets invite more people so we can decide which is better @seladb @tigercosmos @clementperon.

Note: We still have plenty of time because there are lots of warnings even for Common++ so it will take some time to fix PR :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the left one though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just reverted it and placed all new qualifiers to left for now and keep the clang-format default behavior to keep this PR simple. We can completely change by just running clang-format later if left or right decided.

@egecetin egecetin requested a review from Copilot November 19, 2024 19:57

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 21 changed files in this pull request and generated no suggestions.

Files not reviewed (18)
  • Common++/header/GeneralUtils.h: Language not supported
  • Common++/header/IpAddress.h: Language not supported
  • Common++/header/IpUtils.h: Language not supported
  • Common++/header/LRUList.h: Language not supported
  • Common++/header/Logger.h: Language not supported
  • Common++/header/MacAddress.h: Language not supported
  • Common++/header/OUILookup.h: Language not supported
  • Common++/header/PointerVector.h: Language not supported
  • Common++/header/SystemUtils.h: Language not supported
  • Common++/header/TablePrinter.h: Language not supported
  • Common++/src/GeneralUtils.cpp: Language not supported
  • Common++/src/IpAddress.cpp: Language not supported
  • Common++/src/IpUtils.cpp: Language not supported
  • Common++/src/Logger.cpp: Language not supported
  • Common++/src/MacAddress.cpp: Language not supported
  • Common++/src/OUILookup.cpp: Language not supported
  • Common++/src/SystemUtils.cpp: Language not supported
  • Common++/src/TablePrinter.cpp: Language not supported
@egecetin egecetin mentioned this pull request Jan 1, 2025
6 tasks
@egecetin egecetin marked this pull request as ready for review January 1, 2025 18:23
@egecetin egecetin requested a review from seladb as a code owner January 1, 2025 18:23
@@ -0,0 +1,34 @@
Checks: 'cert-*,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I used this configuration to fix issues. Since all of directories are not fixed this file not used for now in CI

@@ -0,0 +1,43 @@
#!/bin/sh
Copy link
Collaborator Author

@egecetin egecetin Jan 1, 2025

Choose a reason for hiding this comment

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

This script for easy local checking. Except Common++ all directories are ignored. It will be replacing the original script after all folders are fixed.

@egecetin
Copy link
Collaborator Author

egecetin commented Jan 1, 2025

Side note looks like gcovr weirdly fails in Fedora 40. Check https://github.com/seladb/PcapPlusPlus/actions/runs/12573299593/job/35046174314. I only added a newline in commit 12e7606 and it passed. It might affect other PRs too please keep in mind that if you see similar error.

Comment on lines +510 to +511
uint32_t m_NetworkPrefix{};
uint32_t m_Mask{};
Copy link
Owner

Choose a reason for hiding this comment

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

Why not set it to zero instead of {}? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is from clang-tidy auto-fix. I don't touch anything as much as possible unless something is broken (unfortunately it messed with OUILookup but fixed) or suggested fixes not applied automatically. {} should be zero for fundamental types if I'm not mistaken

Copy link
Owner

@seladb seladb Jan 8, 2025

Choose a reason for hiding this comment

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

{} should be zero for fundamental types if I'm not mistaken

I believe you're right, but it makes the code less clear. Is there a configuration to ask clang-tidy auto-fix to set it to zero instead?

Comment on lines +598 to +599
uint8_t m_NetworkPrefix[16]{};
uint8_t m_Mask[16]{};
Copy link
Owner

Choose a reason for hiding this comment

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

ditto

Common++/header/Logger.h Outdated Show resolved Hide resolved
Common++/src/Logger.cpp Show resolved Hide resolved
Common++/src/SystemUtils.cpp Show resolved Hide resolved
Comment on lines 373 to 375
struct sigaction action
{
};
Copy link
Owner

Choose a reason for hiding this comment

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

ditto

Common++/src/TablePrinter.cpp Show resolved Hide resolved
Common++/header/SystemUtils.h Show resolved Hide resolved
Common++/src/IpAddress.cpp Outdated Show resolved Hide resolved
Common++/src/IpAddress.cpp Outdated Show resolved Hide resolved
@@ -249,7 +249,7 @@ namespace pcpp
PcapStats stats;
getStatistics(stats);
m_cbOnStatsUpdate(stats, m_cbOnStatsUpdateUserCookie);
multiPlatformSleep(m_IntervalToUpdateStats);
std::this_thread::sleep_for(std::chrono::milliseconds(m_IntervalToUpdateStats));
Copy link
Owner

Choose a reason for hiding this comment

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

This should be:

std::this_thread::sleep_for(std::chrono::seconds(m_IntervalToUpdateStats));

Comment on lines 203 to 205
struct stat info
{
};
Copy link
Owner

Choose a reason for hiding this comment

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

I see you already opened a PR for it: #1677, let's get it merged before this PR?

@@ -364,15 +367,15 @@ namespace pcpp
{
memset(m_Mask, 0, IPV6_ADDR_SIZE);
int remainingPrefixLen = prefixLen;
for (auto byteIndex = 0; byteIndex < IPV6_ADDR_SIZE; byteIndex++)
for (unsigned char& byteIndex : m_Mask)
Copy link
Owner

Choose a reason for hiding this comment

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

We can rename byteIndex to byte and use auto&:

for (auto& byte : m_Mask)
{
    ...
}

@@ -484,10 +488,10 @@ namespace pcpp
uint8_t IPv6Network::getPrefixLen() const
{
uint8_t result = 0;
for (auto byteIndex = 0; byteIndex < IPV6_ADDR_SIZE; byteIndex++)
for (const unsigned char byteIndex : m_Mask)
Copy link
Owner

Choose a reason for hiding this comment

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

We can rename byteIndex to byte and use auto:

for (auto byte : m_Mask)
{
    ...
}

@@ -520,10 +524,10 @@ namespace pcpp
uint64_t IPv6Network::getTotalAddressCount() const
{
int numOfBitset = 0;
for (auto byteIndex = 0; byteIndex < IPV6_ADDR_SIZE; byteIndex++)
for (const unsigned char byteIndex : m_Mask)
Copy link
Owner

Choose a reason for hiding this comment

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

ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants