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

Merged
merged 29 commits into from
Jan 12, 2025
Merged

Clang-tidy fixes for Common++ #1639

merged 29 commits into from
Jan 12, 2025

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.70621% with 43 lines in your changes missing coverage. Please review.

Project coverage is 83.11%. Comparing base (bc5c08d) to head (e5d28d6).
Report is 1 commits behind head on dev.

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.15%   83.11%   -0.04%     
==========================================
  Files         277      277              
  Lines       48185    48207      +22     
  Branches    10165     9913     -252     
==========================================
  Hits        40066    40066              
- Misses       7237     7248      +11     
- Partials      882      893      +11     
Flag Coverage Δ
alpine320 75.10% <73.91%> (-0.06%) ⬇️
fedora40 75.12% <74.45%> (-0.04%) ⬇️
macos-13 80.61% <73.12%> (-0.04%) ⬇️
macos-14 80.61% <73.12%> (-0.04%) ⬇️
macos-15 80.59% <71.89%> (-0.03%) ⬇️
mingw32 70.82% <73.21%> (-0.10%) ⬇️
mingw64 70.78% <73.21%> (-0.10%) ⬇️
npcap 85.24% <81.51%> (-0.07%) ⬇️
rhel94 74.97% <74.45%> (-0.07%) ⬇️
ubuntu2004 58.59% <73.33%> (-0.01%) ⬇️
ubuntu2004-zstd 58.68% <73.33%> (-0.03%) ⬇️
ubuntu2204 74.90% <74.45%> (-0.04%) ⬇️
ubuntu2204-icpx 61.45% <68.11%> (+0.07%) ⬆️
ubuntu2404 75.17% <74.63%> (-0.02%) ⬇️
unittest 83.11% <75.70%> (-0.04%) ⬇️
windows-2019 85.27% <81.51%> (-0.07%) ⬇️
windows-2022 85.30% <81.51%> (-0.07%) ⬇️
winpcap 85.26% <81.51%> (-0.06%) ⬇️
xdp 50.53% <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.

Common++/header/IpAddress.h Show resolved Hide resolved
Common++/header/IpAddress.h Show resolved Hide resolved
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
Common++/src/SystemUtils.cpp Outdated Show resolved Hide resolved
Common++/src/TablePrinter.cpp Show resolved Hide resolved
Common++/header/SystemUtils.h Outdated Show resolved Hide resolved
Common++/src/IpAddress.cpp Outdated Show resolved Hide resolved
Common++/src/IpAddress.cpp Outdated Show resolved Hide resolved
Pcap++/src/PcapLiveDevice.cpp Outdated Show resolved Hide resolved
Common++/src/SystemUtils.cpp Outdated Show resolved Hide resolved
@@ -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)
{
    ...
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed with 3ec344e

@@ -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)
{
    ...
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed with 3ec344e

@@ -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

Copy link
Collaborator Author

@egecetin egecetin Jan 11, 2025

Choose a reason for hiding this comment

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

fixed with cbe3a03

@egecetin egecetin requested a review from seladb January 11, 2025 18:05
@egecetin egecetin merged commit d60c699 into seladb:dev Jan 12, 2025
41 checks passed
@egecetin egecetin deleted the clang-tidy branch January 12, 2025 07:56
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