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

build: remove some gcc-13 compiler warnings #1529

Conversation

federico-sysdig
Copy link
Contributor

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 with std::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?:

NONE

@@ -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')
Copy link
Contributor Author

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];
Copy link
Contributor

Choose a reason for hiding this comment

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

Any comment on this?

Copy link
Contributor Author

@federico-sysdig federico-sysdig Dec 1, 2023

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;
Copy link
Contributor

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?

Copy link
Contributor Author

@federico-sysdig federico-sysdig Dec 1, 2023

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.

@FedeDP
Copy link
Contributor

FedeDP commented Dec 1, 2023

/milestone 0.14.0

@poiana poiana added this to the 0.14.0 milestone Dec 1, 2023
Copy link
Contributor

@FedeDP FedeDP left a 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!

@poiana
Copy link
Contributor

poiana commented Dec 1, 2023

LGTM label has been added.

Git tree hash: 4858b8bc2d20447401b45b91c882bce1a1729e79

@poiana poiana added the approved label Dec 1, 2023
Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Dec 1, 2023

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit 443bca5 into falcosecurity:master Dec 1, 2023
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants