-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C++: Promote cpp/guarded-free out of experimental
#18111
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
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d9b278d
C++: Promote `cpp/guarded-free`
jketema e1f70a0
C++: Add missing `</p>` to qlhelp
jketema fc6c327
C++: Add change note
jketema 6aa7c93
C++: More qlhelp fixes
jketema 8d59159
C++: Fix qlref file
jketema 088a3ef
Update cpp/ql/src/Best Practices/GuardedFree.qhelp
jketema f9d9f9b
Update cpp/ql/src/Best Practices/GuardedFree.qhelp
jketema 6d37efc
Update cpp/ql/src/Best Practices/GuardedFree.qhelp
jketema 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.
16 changes: 13 additions & 3 deletions
16
...rimental/Best Practices/GuardedFree.qhelp → cpp/ql/src/Best Practices/GuardedFree.qhelp
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 |
|---|---|---|
| @@ -1,18 +1,28 @@ | ||
| <!DOCTYPE qhelp SYSTEM "qhelp.dtd"> | ||
| <!DOCTYPE qhelp PUBLIC | ||
| "-//Semmle//qhelp//EN" | ||
| "qhelp.dtd"> | ||
| <qhelp> | ||
|
|
||
| <overview> | ||
| <p>The <code>free</code> function, which deallocates heap memory, may accept a NULL pointer and take no action. Therefore, it is unnecessary to check its argument for the value of NULL before a function call to <code>free</code>. As such, these guards may hinder performance and readability.</p> | ||
| </overview> | ||
|
|
||
| <recommendation> | ||
| <p>A function call to <code>free</code> should not depend upon the value of its argument. Delete the <code>if</code> condition preceeding a function call to <code>free</code> when its only purpose is to check the value of the pointer to be freed.</p> | ||
| <p>A function call to <code>free</code> should not depend upon the value of its argument. Delete the condition preceding a function call to <code>free</code> when its only purpose is to check the value of the pointer to be freed.</p> | ||
| </recommendation> | ||
|
|
||
| <example> | ||
| <sample src = "GuardedFree.cpp" /> | ||
|
|
||
| <p>In this example the condition checking the value of <code>foo</code> can be deleted.</p> | ||
jketema marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| </example> | ||
|
|
||
| <references> | ||
| <li> | ||
| The Open Group Base Specifications Issue 7, 2018 Edition: | ||
| <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html">free - free allocated memory</a> | ||
jketema marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </li> | ||
| </references> | ||
| </qhelp> | ||
|
|
||
| </qhelp> | ||
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 |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
| * @id cpp/guarded-free | ||
| * @tags maintainability | ||
| * readability | ||
| * experimental | ||
| */ | ||
|
|
||
| import cpp | ||
|
|
||
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,4 @@ | ||
| --- | ||
| category: newQuery | ||
| --- | ||
| * Added a new high-precision quality query, `cpp/guarded-free`, which detects useless NULL pointer checks before calls to `free`. A variation of this query was originally contributed as an [experimental query by @mario-campos](https://github.com/github/codeql/pull/16331). |
1 change: 0 additions & 1 deletion
1
cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/GuardedFree.qlref
This file was deleted.
Oops, something went wrong.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
cpp/ql/test/query-tests/Best Practices/GuardedFree/GuardedFree.qlref
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 @@ | ||
| Best Practices/GuardedFree.ql |
File renamed without changes.
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.