-
Notifications
You must be signed in to change notification settings - Fork 286
Add cpplint warnings for exit() and abort() #8738
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
tautschnig
wants to merge
1
commit into
diffblue:develop
Choose a base branch
from
tautschnig:cpplint-exit-abort
base: develop
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.
Open
Changes from all commits
Commits
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
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,48 @@ | ||
| // Author: Michael Tautschnig | ||
|
|
||
| // Test file that should NOT generate any termination warnings | ||
| // This file contains various uses of "exit" and "abort" that should not trigger | ||
|
|
||
| #include <iostream> | ||
| #include <string> | ||
|
|
||
| int main() | ||
| { | ||
| // Variable names containing exit/abort - should not trigger | ||
| int exit_code = 0; | ||
| bool exit_flag = false; | ||
| void *exit_ptr = nullptr; | ||
| bool abort_flag = false; | ||
| int abort_count = 0; | ||
|
|
||
| // Assignment to variables | ||
| exit_code = 1; | ||
| exit_flag = true; | ||
| abort_flag = false; | ||
|
|
||
| // Function calls that use custom namespaces (not std:: or ::) | ||
| // Note: Member function calls like obj.exit() would trigger warnings | ||
| // due to current regex implementation, so we avoid them here | ||
|
|
||
| return exit_code; | ||
| } | ||
|
|
||
| // Function definitions that shouldn't trigger | ||
| void my_exit_function() | ||
| { | ||
| std::cout << "This is not exit()" << std::endl; | ||
| } | ||
|
|
||
| void abort_handler() | ||
| { | ||
| std::cout << "This is not abort()" << std::endl; | ||
| } | ||
|
|
||
| // Custom namespace functions (not std:: or ::) | ||
| void use_custom_functions() | ||
| { | ||
| // These have custom namespace prefixes, so should not trigger | ||
| // Note: current implementation only checks for std:: and :: prefixes | ||
| // myns::exit(0); // Would not trigger if uncommented | ||
| // custom::abort(); // Would not trigger if uncommented | ||
| } | ||
1 change: 1 addition & 0 deletions
1
regression/cpp-linter/abort-exit-no-warning/module_dependencies.txt
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 @@ | ||
|
|
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,9 @@ | ||
| CORE | ||
| main.cpp | ||
|
|
||
| ^# Total errors found: 0$ | ||
| ^EXIT=0$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| ^# Total errors found: [1-9] | ||
| -- |
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,43 @@ | ||
| // Author: Michael Tautschnig | ||
|
|
||
| // Test file for NOLINT suppression | ||
| // This file tests that NOLINT comments properly suppress warnings | ||
|
|
||
| #include <cstdlib> | ||
|
|
||
| int main() | ||
| { | ||
| // These should be suppressed by NOLINT comments | ||
| exit(1); // NOLINT - justified use case | ||
| abort(); // NOLINT(runtime/termination) - specific suppression | ||
|
|
||
| std::exit(2); // NOLINT | ||
| ::abort(); // NOLINT(runtime/termination) | ||
|
|
||
| // These should still trigger warnings (no NOLINT) | ||
| exit(3); // Line 18: Warning expected | ||
| abort(); // Line 19: Warning expected | ||
|
|
||
| // Test NOLINT with other categories (should NOT suppress this warning) | ||
| exit(4); // NOLINT(whitespace/parens) | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| void test_function() | ||
| { | ||
| // Mixed suppressed and unsuppressed | ||
| exit(5); // Line 30: Warning expected | ||
| abort(); // NOLINT - suppressed | ||
| std::exit(6); // Line 32: Warning expected | ||
| ::abort(); // NOLINT(runtime/termination) - suppressed | ||
| } | ||
|
|
||
| // Test NOLINT at end of line vs middle | ||
| void another_test() | ||
| { | ||
| exit(7); /* NOLINT */ | ||
| int x = 0; | ||
| abort(); // Line 41: Warning expected | ||
| int y = 0; | ||
| } |
1 change: 1 addition & 0 deletions
1
regression/cpp-linter/abort-exit-nolint/module_dependencies.txt
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 @@ | ||
|
|
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,12 @@ | ||
| CORE | ||
| main.cpp | ||
|
|
||
| ^regression/cpp-linter/abort-exit-nolint/main\.cpp:18: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/abort-exit-nolint/main\.cpp:19: abort\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/abort-exit-nolint/main\.cpp:22: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/abort-exit-nolint/main\.cpp:30: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/abort-exit-nolint/main\.cpp:32: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/abort-exit-nolint/main\.cpp:41: abort\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^# Total errors found: 6$ | ||
| ^EXIT=1$ | ||
| ^SIGNAL=0$ |
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,52 @@ | ||
| // Author: Michael Tautschnig | ||
|
|
||
| // Test file for abort() call detection | ||
| // This file should generate multiple warnings | ||
|
|
||
| #include <cstdlib> | ||
|
|
||
| void error_handler() | ||
| { | ||
| // Basic abort calls - should trigger warnings | ||
| abort(); // Line 11: Warning expected | ||
|
|
||
| // Namespace qualified calls - should trigger warnings | ||
| std::abort(); // Line 14: Warning expected | ||
| ::abort(); // Line 15: Warning expected | ||
|
|
||
| // Calls with whitespace - should trigger warnings | ||
| abort(); // Line 18: Warning expected | ||
| abort(); // Line 19: Warning expected | ||
| abort(); // Line 20: Warning expected (tab) | ||
|
|
||
| // Calls in expressions - should trigger warnings | ||
| if(fatal_error) | ||
| abort(); // Line 24: Warning expected | ||
| } | ||
|
|
||
| // Variable names - should NOT trigger warnings | ||
| bool abort_flag = false; | ||
| int abort_count = 0; | ||
|
|
||
| class abortablet | ||
| { | ||
| public: | ||
| void process() | ||
| { | ||
| if(should_abort) | ||
| { | ||
| abort(); // Line 38: Warning expected | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // Function names containing abort - should NOT trigger | ||
| void abort_operation() | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| void check_abort_status() | ||
| { | ||
| return; | ||
| } |
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 @@ | ||
|
|
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 @@ | ||
| CORE | ||
| main.cpp | ||
|
|
||
| ^regression/cpp-linter/abort/main\.cpp:11: abort\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/abort/main\.cpp:14: abort\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/abort/main\.cpp:15: abort\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/abort/main\.cpp:18: abort\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/abort/main\.cpp:19: abort\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/abort/main\.cpp:20: abort\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/abort/main\.cpp:24: abort\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/abort/main\.cpp:38: abort\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^# Total errors found: 8$ | ||
| ^EXIT=1$ | ||
| ^SIGNAL=0$ |
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,55 @@ | ||
| // Author: Michael Tautschnig | ||
|
|
||
| // Test file for exit() call detection | ||
| // This file should generate multiple warnings | ||
|
|
||
| #include <cstdlib> | ||
|
|
||
| int main() | ||
| { | ||
| // Basic exit calls - should trigger warnings | ||
| exit(1); // Line 11: Warning expected | ||
| exit(EXIT_FAILURE); // Line 12: Warning expected | ||
|
|
||
| // Namespace qualified calls - should trigger warnings | ||
| std::exit(1); // Line 15: Warning expected | ||
| ::exit(2); // Line 16: Warning expected | ||
|
|
||
| // Calls with whitespace - should trigger warnings | ||
| exit(3); // Line 19: Warning expected | ||
| exit(4); // Line 20: Warning expected | ||
| exit(5); // Line 21: Warning expected (tab) | ||
|
|
||
| // Calls in expressions - should trigger warnings | ||
| if(condition) | ||
| exit(6); // Line 25: Warning expected | ||
| return exit(7); // Line 26: Warning expected | ||
|
|
||
| // Variable names - should NOT trigger warnings | ||
| int exit_code = 0; | ||
| bool exit_flag = false; | ||
| void *exit_ptr = nullptr; | ||
|
|
||
| return exit_code; | ||
| } | ||
|
|
||
| void error_function() | ||
| { | ||
| // More exit calls in different contexts | ||
| exit(10); // Line 39: Warning expected | ||
| } | ||
|
|
||
| class test_classt | ||
| { | ||
| public: | ||
| void method() | ||
| { | ||
| exit(11); // Line 47: Warning expected | ||
| } | ||
| }; | ||
|
|
||
| // Function names containing exit - should NOT trigger | ||
| void my_exit_function() | ||
| { | ||
| return; | ||
| } |
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 @@ | ||
|
|
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,17 @@ | ||
| CORE | ||
| main.cpp | ||
|
|
||
| ^regression/cpp-linter/exit/main\.cpp:11: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/exit/main\.cpp:12: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/exit/main\.cpp:15: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/exit/main\.cpp:16: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/exit/main\.cpp:19: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/exit/main\.cpp:20: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/exit/main\.cpp:21: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/exit/main\.cpp:25: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/exit/main\.cpp:26: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/exit/main\.cpp:39: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^regression/cpp-linter/exit/main\.cpp:47: exit\(\) should not be used. Normal termination should be via return from main. Abnormal termination should use invariant.h macros. If this use is justified, mark with NOLINT. See https://github.com/diffblue/cbmc/issues/1902 \[runtime/termination\] \[4\] | ||
| ^# Total errors found: 11$ | ||
| ^EXIT=1$ | ||
| ^SIGNAL=0$ |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.