Skip to content

Add dummy macros for conditionally defined macros #211

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

Merged
merged 3 commits into from
Feb 27, 2025

Conversation

lumynou5
Copy link
Contributor

cppcheck reports "unknownMacro" when a conditionally defined macro is used.

This patch adds dummy macros to make code pass the static analytics without other effects. The assignments and increments make cppcheck consider the variables are used to suppress potential reports about uninitialized variables, unused variables, and can-be-constant variables. The pointers with value 1 instead of NULL suppress reports about indirectly getting value of null pointers.

Closes #210.

Change-Id: Ia8db49c0c71ab82d5da10ce389f57ebb69c99051

cppcheck reports "unknownMacro" when a conditionally defined macro is
used.

This patch adds dummy macros to make code pass the static analytics
without other effects.  The assignments and increments make cppcheck
consider the variables are used to suppress potential reports about
uninitialized variables, unused variables, and can-be-constant
variables.  The pointers with value 1 instead of NULL suppress reports
about indirectly getting value of null pointers.

Closes sysprog21#210.

Change-Id: Ia8db49c0c71ab82d5da10ce389f57ebb69c99051
Change-Id: I1da359df006f058c3e27a0d4bc91b50c4441a1da
Change-Id: I85c21c24bbd5856a5a22cbd983f5150a56c13345
@jserv jserv merged commit 1d68fae into sysprog21:master Feb 27, 2025
1 of 2 checks passed
@jserv
Copy link
Contributor

jserv commented Feb 27, 2025

Thank @lumynou5 for contributing!

Mike1117 pushed a commit to Mike1117/lab0-c that referenced this pull request Feb 27, 2025
Cppcheck reports "unknownMacro" when a conditionally defined macro is
used.

This patch adds dummy macros to make code pass the static analytics
without other effects.  The assignments and increments make cppcheck
consider the variables are used to suppress potential reports about
uninitialized variables, unused variables, and can-be-constant
variables.  The pointers with value 1 instead of NULL suppress reports
about indirectly getting value of null pointers.

Closes sysprog21#210

Change-Id: Ia8db49c0c71ab82d5da10ce389f57ebb69c99051
yy214123 pushed a commit to yy214123/lab0-c that referenced this pull request Feb 27, 2025
Cppcheck reports "unknownMacro" when a conditionally defined macro is
used.

This patch adds dummy macros to make code pass the static analytics
without other effects.  The assignments and increments make cppcheck
consider the variables are used to suppress potential reports about
uninitialized variables, unused variables, and can-be-constant
variables.  The pointers with value 1 instead of NULL suppress reports
about indirectly getting value of null pointers.

Closes sysprog21#210

Change-Id: Ia8db49c0c71ab82d5da10ce389f57ebb69c99051
@backink
Copy link
Contributor

backink commented Feb 28, 2025

The anonymous bit field cause the cppcheck (version 2.13.0) to report "Label 'int' is not used. [unusedLabel]" during static analysis.

@lumynou5
Copy link
Contributor Author

lumynou5 commented Feb 28, 2025

@backink I suspect it's a bug of Cppcheck while it incorrectly recognizes int as a label. It looks similar to ticket #10886, but the latter was fixed 3 years ago. Try updating your Cppcheck.

@backink
Copy link
Contributor

backink commented Mar 1, 2025

Hi @lumynou5
I solved the problem by upgrading cppcheck to the newest version, but the required version announced in the project instruction is over 1.90. And cppcheck 2.13 is the official release version of Ubuntu 24.04, which is the newest LTS version, that is, compiling cppcheck manually from source code should be added as a prerequisite to the instruction, otherwise all the participants will encounter this issue.
In my opinion, this commit should be fixed to be compatible with the default version that Ubuntu 24.04 provides.
Thanks

@lumynou5
Copy link
Contributor Author

lumynou5 commented Mar 1, 2025

this commit should be fixed to be compatible with the default version that Ubuntu 24.04 provides.

I think it's not a compatibility issue, but it's indeed better to work with 2.13.0. Other than installing from other repositories or building from source, the only option is trying not to trigger the false positive. Does giving the data member a name help Cppcheck parse it correctly without other errors?

If so, you may open a pull request to change it like

-     for (entry = (void *) 1; sizeof(struct { int : -1; }); ++(entry))
+     for (entry = (void *) 1; sizeof(struct { int i : -1; }); ++(entry))

and probably note the reason of adding the useless name.

hahaB7 pushed a commit to hahaB7/lab0-c that referenced this pull request Mar 3, 2025
Cppcheck reports "unknownMacro" when a conditionally defined macro is
used.

This patch adds dummy macros to make code pass the static analytics
without other effects.  The assignments and increments make cppcheck
consider the variables are used to suppress potential reports about
uninitialized variables, unused variables, and can-be-constant
variables.  The pointers with value 1 instead of NULL suppress reports
about indirectly getting value of null pointers.

Closes sysprog21#210

Change-Id: Ia8db49c0c71ab82d5da10ce389f57ebb69c99051
I-Ying-Tsai pushed a commit to I-Ying-Tsai/lab0-c that referenced this pull request Mar 21, 2025
Cppcheck reports "unknownMacro" when a conditionally defined macro is
used.

This patch adds dummy macros to make code pass the static analytics
without other effects.  The assignments and increments make cppcheck
consider the variables are used to suppress potential reports about
uninitialized variables, unused variables, and can-be-constant
variables.  The pointers with value 1 instead of NULL suppress reports
about indirectly getting value of null pointers.

Closes sysprog21#210

Change-Id: Ia8db49c0c71ab82d5da10ce389f57ebb69c99051
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.

Add dummy macros for conditionally defined macros
3 participants