-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18111 from jketema/guarded-free
C++: Promote `cpp/guarded-free` out of experimental
- Loading branch information
Showing
8 changed files
with
20 additions
and
7 deletions.
There are no files selected for viewing
File renamed without changes.
20 changes: 15 additions & 5 deletions
20
...rimental/Best Practices/GuardedFree.qhelp → cpp/ql/src/Best Practices/GuardedFree.qhelp
This file contains 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> | ||
<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 the 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> | ||
|
||
</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> | ||
<a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html">free - free allocated memory</a>. | ||
</li> | ||
</references> | ||
</qhelp> | ||
|
||
</qhelp> |
This file contains 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 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 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.