-
Notifications
You must be signed in to change notification settings - Fork 683
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
base: dev
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@egecetin please see this comment: #1637 (comment) |
.clang-format
Outdated
@@ -21,4 +21,5 @@ BreakBeforeBraces: Custom | |||
BraceWrapping: | |||
SplitEmptyFunction: false | |||
AfterCaseLabel: true | |||
QualifierAlignment: Left |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@@ -0,0 +1,34 @@ | |||
Checks: 'cert-*, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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. |
uint32_t m_NetworkPrefix{}; | ||
uint32_t m_Mask{}; |
There was a problem hiding this comment.
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 {}
? 🤔
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
uint8_t m_NetworkPrefix[16]{}; | ||
uint8_t m_Mask[16]{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Common++/src/SystemUtils.cpp
Outdated
struct sigaction action | ||
{ | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -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)); |
There was a problem hiding this comment.
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));
Common++/src/SystemUtils.cpp
Outdated
struct stat info | ||
{ | ||
}; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Fix various clang-tidy warnings for Common++
Requires #1677