-
Notifications
You must be signed in to change notification settings - Fork 76
Michaelrfairhurst/rule 4 1 3 detect data races #1077
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
Open
MichaelRFairhurst
wants to merge
6
commits into
michaelrfairhurst/package-undefined-behavior
Choose a base branch
from
michaelrfairhurst/rule-4-1-3-detect-data-races
base: michaelrfairhurst/package-undefined-behavior
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+589
−142
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ce3d937
Detect data races
MichaelRFairhurst d336752
Commit missing files
MichaelRFairhurst 65e525d
Merge branch 'michaelrfairhurst/package-undefined-behavior' into mich…
MichaelRFairhurst 3a6af4e
Regenenate metadata
MichaelRFairhurst e7a35a2
Merge branch 'michaelrfairhurst/package-undefined-behavior' into mich…
MichaelRFairhurst 858bde4
Merge branch 'michaelrfairhurst/package-undefined-behavior' into mich…
MichaelRFairhurst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
...n/test/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // GENERATED FILE - DO NOT MODIFY | ||
| import codingstandards.cpp.rules.possibledataracebetweenthreadsshared.PossibleDataRaceBetweenThreadsShared | ||
| import codingstandards.c.Objects as CObjects | ||
| import codingstandards.c.SubObjects as CSubObjects | ||
|
|
||
| module TestFileConfig implements PossibleDataRaceBetweenThreadsSharedConfigSig { | ||
| Query getQuery() { result instanceof TestQuery } | ||
|
|
||
| class ObjectIdentity = CObjects::ObjectIdentity; | ||
|
|
||
| class SubObject = CSubObjects::SubObject; | ||
| } | ||
|
|
||
| import PossibleDataRaceBetweenThreadsShared<TestFileConfig> |
132 changes: 132 additions & 0 deletions
132
c/common/test/rules/possibledataracebetweenthreadsshared/test.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| #include "locale.h" | ||
| #include "stdio.h" | ||
| #include "stdlib.h" | ||
| #include "string.h" | ||
| #include "threads.h" | ||
| #include "time.h" | ||
| #include "uchar.h" | ||
| #include "wchar.h" | ||
|
|
||
| int g1; | ||
| int g2; | ||
| int g3; | ||
| int g4; | ||
| mtx_t g4_lock; | ||
| int g5; | ||
| mtx_t g5_lock; | ||
|
|
||
| void single_thread1_reads_g1(void *p) { | ||
| g1; // COMPLIANT | ||
| } | ||
|
|
||
| void many_thread2_reads_g1(void *p) { | ||
| g1; // COMPLIANT | ||
| } | ||
|
|
||
| void single_thread3_reads_g2(void *p) { | ||
| g2; // COMPLIANT | ||
| } | ||
|
|
||
| void single_thread4_writes_g2(void *p) { | ||
| g2 = 1; // NON-COMPLIANT | ||
| } | ||
|
|
||
| void many_thread5_writes_g3(void *p) { | ||
| g3 = 1; // NON-COMPLIANT | ||
| } | ||
|
|
||
| void single_thread6_reads_g4_locked(void *p) { | ||
| mtx_lock(&g4_lock); | ||
| g4; // COMPLIANT | ||
| } | ||
|
|
||
| void single_thread7_writes_g4_locked(void *p) { | ||
| mtx_lock(&g4_lock); | ||
| g4 = 1; // COMPLIANT | ||
| } | ||
|
|
||
| void many_thread8_writes_g5_locked(void *p) { | ||
| mtx_lock(&g5_lock); | ||
| g5 = 1; // COMPLIANT | ||
| } | ||
|
|
||
| struct { | ||
| int m1; | ||
| int m2; | ||
| } g6; | ||
|
|
||
| void single_thread9_writes_g6_m1(void *p) { | ||
| g6.m1 = 1; // COMPLIANT | ||
| } | ||
|
|
||
| void single_thread10_writes_g6_m2(void *p) { | ||
| g6.m2 = 1; // COMPLIANT | ||
| } | ||
|
|
||
| struct { | ||
| int m1; | ||
| } g7; | ||
|
|
||
| void single_thread11_writes_g7_m1(void *p) { | ||
| g7.m1 = 1; // NON-COMPLIANT | ||
| } | ||
|
|
||
| void single_thread12_writes_g7_m1(void *p) { | ||
| g7.m1 = 1; // NON-COMPLIANT | ||
| } | ||
|
|
||
| void many_thread13_calls_nonreentrant_funcs(void *p) { | ||
| setlocale(LC_ALL, "C"); // NON-COMPLIANT | ||
| tmpnam(""); // NON-COMPLIANT | ||
| rand(); // NON-COMPLIANT | ||
| srand(0); // NON-COMPLIANT | ||
| getenv("PATH"); // NON-COMPLIANT | ||
| getenv_s(NULL, NULL, 0, NULL); // NON-COMPLIANT | ||
| strtok("a", "b"); // NON-COMPLIANT | ||
| strerror(0); // NON-COMPLIANT | ||
| asctime(NULL); // NON-COMPLIANT | ||
| ctime(NULL); // NON-COMPLIANT | ||
| gmtime(NULL); // NON-COMPLIANT | ||
| localtime(NULL); // NON-COMPLIANT | ||
| mbrtoc16(NULL, NULL, 0, NULL); // NON-COMPLIANT | ||
| mbrtoc32(NULL, NULL, 0, NULL); // NON-COMPLIANT | ||
| c16rtomb(NULL, 0, NULL); // NON-COMPLIANT | ||
| c32rtomb(NULL, 0, NULL); // NON-COMPLIANT | ||
| mbrlen(NULL, 0, NULL); // NON-COMPLIANT | ||
| mbrtowc(NULL, NULL, 0, NULL); // NON-COMPLIANT | ||
| wcrtomb(NULL, 0, NULL); // NON-COMPLIANT | ||
| mbsrtowcs(NULL, NULL, 0, NULL); // NON-COMPLIANT | ||
| wcsrtombs(NULL, NULL, 0, NULL); // NON-COMPLIANT | ||
| } | ||
|
|
||
| int main(int argc, char *argv[]) { | ||
| thrd_t single_thread1; | ||
| thrd_t many_thread2; | ||
| thrd_t single_thread3; | ||
| thrd_t single_thread4; | ||
| thrd_t many_thread5; | ||
| thrd_t single_thread6; | ||
| thrd_t single_thread7; | ||
| thrd_t many_thread8; | ||
| thrd_t single_thread9; | ||
| thrd_t single_thread10; | ||
| thrd_t single_thread11; | ||
| thrd_t single_thread12; | ||
| thrd_t many_thread13; | ||
|
|
||
| thrd_create(&single_thread1, single_thread1_reads_g1, NULL); | ||
| thrd_create(&single_thread3, single_thread3_reads_g2, NULL); | ||
| thrd_create(&single_thread4, single_thread4_writes_g2, NULL); | ||
| thrd_create(&single_thread6, single_thread6_reads_g4_locked, NULL); | ||
| thrd_create(&single_thread7, single_thread7_writes_g4_locked, NULL); | ||
| thrd_create(&single_thread9, single_thread9_writes_g6_m1, NULL); | ||
| thrd_create(&single_thread10, single_thread10_writes_g6_m2, NULL); | ||
| thrd_create(&single_thread11, single_thread11_writes_g7_m1, NULL); | ||
| thrd_create(&single_thread12, single_thread12_writes_g7_m1, NULL); | ||
| for (;;) { | ||
| thrd_create(&many_thread2, many_thread2_reads_g1, NULL); | ||
| thrd_create(&many_thread5, many_thread5_writes_g3, NULL); | ||
| thrd_create(&many_thread8, many_thread8_writes_g5_locked, NULL); | ||
| thrd_create(&many_thread13, many_thread13_calls_nonreentrant_funcs, NULL); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
c/misra/test/rules/DIR-5-1/PossibleDataRaceBetweenThreads.qlref
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
c/misra/test/rules/DIR-5-1/PossibleDataRaceBetweenThreads.testref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| c/common/test/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.ql |
2 changes: 2 additions & 0 deletions
2
change_notes/2026-03-09-possible-data-race-between-threads-shared.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - `DIR-5-1` - `PossibleDataRaceBetweenThreads.ql`: | ||
| - Refactored implementation into a shared library (`PossibleDataRaceBetweenThreadsShared.qll`) to allow reuse by MISRA C++ 2023 `RULE-4-1-3`. No change in results is expected for `DIR-5-1`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
strtok("a", "b")on line 85 is annotatedNON-COMPLIANTbut has no corresponding entry in the.expectedfile. This is caused by the"strok"typo in the shared implementation (should be"strtok"). Once the typo is fixed, this will produce a result and the.expectedfile will need to be updated accordingly.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.
filed #1078