diff --git a/cpp/ql/src/experimental/Best Practices/GuardedFree.cpp b/cpp/ql/src/Best Practices/GuardedFree.cpp similarity index 100% rename from cpp/ql/src/experimental/Best Practices/GuardedFree.cpp rename to cpp/ql/src/Best Practices/GuardedFree.cpp diff --git a/cpp/ql/src/experimental/Best Practices/GuardedFree.qhelp b/cpp/ql/src/Best Practices/GuardedFree.qhelp similarity index 55% rename from cpp/ql/src/experimental/Best Practices/GuardedFree.qhelp rename to cpp/ql/src/Best Practices/GuardedFree.qhelp index 77fdd4670008..c2dc5cb36d78 100644 --- a/cpp/ql/src/experimental/Best Practices/GuardedFree.qhelp +++ b/cpp/ql/src/Best Practices/GuardedFree.qhelp @@ -1,18 +1,28 @@ - + + -

The free 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 free. As such, these guards may hinder performance and readability.

+

The free 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 free. As such, these guards may hinder performance and readability.

+ -

A function call to free should not depend upon the value of its argument. Delete the if condition preceeding a function call to free when its only purpose is to check the value of the pointer to be freed.

+

A function call to free should not depend upon the value of its argument. Delete the condition preceding a function call to free when its only purpose is to check the value of the pointer to be freed.

+ + +

In this example, the condition checking the value of foo can be deleted.

+
+
  • The Open Group Base Specifications Issue 7, 2018 Edition: - free - free allocated memory + free - free allocated memory.
  • -
    \ No newline at end of file + + diff --git a/cpp/ql/src/experimental/Best Practices/GuardedFree.ql b/cpp/ql/src/Best Practices/GuardedFree.ql similarity index 98% rename from cpp/ql/src/experimental/Best Practices/GuardedFree.ql rename to cpp/ql/src/Best Practices/GuardedFree.ql index 66c7a31111b5..ea81a7158282 100644 --- a/cpp/ql/src/experimental/Best Practices/GuardedFree.ql +++ b/cpp/ql/src/Best Practices/GuardedFree.ql @@ -8,7 +8,6 @@ * @id cpp/guarded-free * @tags maintainability * readability - * experimental */ import cpp diff --git a/cpp/ql/src/change-notes/2014-11-26-guarded-free.md b/cpp/ql/src/change-notes/2014-11-26-guarded-free.md new file mode 100644 index 000000000000..4280025a04f6 --- /dev/null +++ b/cpp/ql/src/change-notes/2014-11-26-guarded-free.md @@ -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). diff --git a/cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/GuardedFree.qlref b/cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/GuardedFree.qlref deleted file mode 100644 index e28bdae39916..000000000000 --- a/cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/GuardedFree.qlref +++ /dev/null @@ -1 +0,0 @@ -experimental/Best Practices/GuardedFree.ql diff --git a/cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/GuardedFree.expected b/cpp/ql/test/query-tests/Best Practices/GuardedFree/GuardedFree.expected similarity index 100% rename from cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/GuardedFree.expected rename to cpp/ql/test/query-tests/Best Practices/GuardedFree/GuardedFree.expected diff --git a/cpp/ql/test/query-tests/Best Practices/GuardedFree/GuardedFree.qlref b/cpp/ql/test/query-tests/Best Practices/GuardedFree/GuardedFree.qlref new file mode 100644 index 000000000000..d64671f08c33 --- /dev/null +++ b/cpp/ql/test/query-tests/Best Practices/GuardedFree/GuardedFree.qlref @@ -0,0 +1 @@ +Best Practices/GuardedFree.ql diff --git a/cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/test.cpp b/cpp/ql/test/query-tests/Best Practices/GuardedFree/test.cpp similarity index 100% rename from cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/test.cpp rename to cpp/ql/test/query-tests/Best Practices/GuardedFree/test.cpp