Skip to content

Add missing STD Library Identifiers#7325

Merged
danmar merged 6 commits intocppcheck-opensource:mainfrom
wienans:feature/std-lib-literals
Mar 8, 2025
Merged

Add missing STD Library Identifiers#7325
danmar merged 6 commits intocppcheck-opensource:mainfrom
wienans:feature/std-lib-literals

Conversation

@wienans
Copy link
Copy Markdown
Contributor

@wienans wienans commented Feb 23, 2025

Added a STDLIB_IDENTIFIERS for C11 as well as updated the C99 once based on,

C99: https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf
C11: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

in the misra.py

@wienans wienans force-pushed the feature/std-lib-literals branch from 75edd8c to a5a449b Compare February 23, 2025 16:49
Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

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

hmm.. some tests would be nice. Do you have some idea? I don't feel we need to test this in full but some kind of generic tests would be nice.. maybe ensure C11_STDLIB_IDENTIFIERS extends C99_STDLIB_IDENTIFIERS, make a few isStdLibId calls to make sure it works, ..

Comment thread addons/misra.py Outdated
@wienans
Copy link
Copy Markdown
Contributor Author

wienans commented Feb 24, 2025

hmm.. some tests would be nice. Do you have some idea? I don't feel we need to test this in full but some kind of generic tests would be nice.. maybe ensure C11_STDLIB_IDENTIFIERS extends C99_STDLIB_IDENTIFIERS, make a few isStdLibId calls to make sure it works, ..

@danmar Test suggestions sound good, I can add that. is there already a test file where the misra.py is „unit tested“? I only found the .c file which tests the detections. If yes could you link the file where I should add it, if no could you make a suggestion how you would like to have the test added?

with test suggestions I don’t have additional ideas, the thing is it’s only a big list of keywords so there is not much to test, apart of the suggestions you already mentioned.

@wienans
Copy link
Copy Markdown
Contributor Author

wienans commented Mar 1, 2025

@danmar added a Test and also checked the isKeyword additionally to isStdLib and fixed a typo there, too.
Additionally i changed the switching std identifieres for C11 from a specific C11 check to else. Therefore all standards after C11 will get the C11 Std Lib Identifiers and Keywords.

If it is fine from your side it can be merged.

@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Mar 8, 2025

@wienans thanks! I wonder, is your name added in https://github.com/danmar/cppcheck/blob/main/AUTHORS yet?

@wienans wienans deleted the feature/std-lib-literals branch March 8, 2025 11:36
@wienans
Copy link
Copy Markdown
Contributor Author

wienans commented Mar 8, 2025

@danmar actually no i am not in it. You can add me as Sven Wienand

danmar pushed a commit that referenced this pull request May 12, 2025
I am not sure why the misra check for 17.3 was reduced to while and if
statements but i think that shouldn't be the case.

Now it should detect more / all functions which are implicitly called.

I had a bit of a issue with function pointer defintion as the tokens

```
int16_t ( * misra_8_2_p_a ) ()
```
cause the detection to trigger on the int16_t. But i filtered these
false function pointer detection's explicitly.


I also updated the test with the expected errors. As C89 is used i
needed to add more expected 17.3 as needed.
* printf_s
* UINT32_C
* va_copy

are all not present in C89. But even if we bump up to C11 this PR
#7325 would need to be merged
before hand to actually get all the needed Identifiers.
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.

2 participants