-
Notifications
You must be signed in to change notification settings - Fork 169
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
build: remove some gcc-13 compiler warnings #1529
build: remove some gcc-13 compiler warnings #1529
Conversation
Signed-off-by: Federico Aponte <[email protected]>
@@ -70,7 +70,7 @@ const char *scap_get_ppm_sc_name(ppm_sc_code sc) | |||
ASSERT(sc >= 0 && sc < PPM_SC_MAX); | |||
|
|||
/* Lazy loading */ | |||
if(g_ppm_sc_names[0] && (strcmp(g_ppm_sc_names[0], "") == 0)) | |||
if(g_ppm_sc_names[0][0] == '\0') |
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.
The warning was lamenting that g_ppm_sc_names[n] is a fixed-size array and, as such, cannot be null. The change from calling strcmp
against an empty string literal to checking that the first character in the array is \0
is an extra that I added thinking it is equivalent, yet simpler and more efficient.
Feel free to comment on this.
@@ -142,7 +142,7 @@ class cycle_writer { | |||
// we don't know what's what at first | |||
// we just leave this hanging. | |||
// | |||
char m_limit_format[6]; | |||
char m_limit_format[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.
Any comment on this?
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.
Sure. The buffer is used to hold a format that contains a variable integer, the number of digits to be used. This number will most likely, in all realistic cases, be one digit long; however, the compiler, in its infinite wisdom, was lamenting that we were printing in the buffer a number that could potentially not fit in it. I thought that an extra 10 bytes were worth silencing the compiler.
sinsp_container_type s_cri_runtime_type = CT_CRI; | ||
std::string s_cri_unix_socket_path; | ||
bool s_cri_extra_queries = true; | ||
inline std::vector<std::string> s_cri_unix_socket_paths; |
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.
Care to explain why was this needed?
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.
Absolutely. This is a header file, as such it could be included in several compilation units. This is not the case today, so there is no problem, but if it were included again we'd have a linker error for duplicate symbols. Inline global variables are a way to tell the compiler/linker that only one instance of that should be created, regardless of the number of times it is encountered in different compilation units.
The other approach would be to declare it as external and define it only once in a separate .cpp file; we now have the inline option since we upgraded the C++ standard a while ago.
/milestone 0.14.0 |
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.
/approve
Thanks for the explanations!
LGTM label has been added. Git tree hash: 4858b8bc2d20447401b45b91c882bce1a1729e79
|
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.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Andreagit97, FedeDP, federico-sysdig The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
Any specific area of the project related to this PR?
/area build
Does this PR require a change in the driver versions?
no
What this PR does / why we need it:
This is another fix of a number of compiler warnings that came up during a build with a recent gcc toolchain (13.2.1).
Also, the usage of macro
MIN
has been replaced withstd::min
for C++ sources. A duplicate macro and its usages for C sources have, of course, been kept.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: