C++: Incorporate docs review comments

This commit is contained in:
Jonas Jensen 2019-01-11 14:16:00 +01:00
Родитель 7ff94e894a
Коммит ca3554dcc6
3 изменённых файлов: 5 добавлений и 6 удалений

Просмотреть файл

@ -8,7 +8,7 @@
| **Query** | **Tags** | **Purpose** |
|-----------------------------|-----------|--------------------------------------------------------------------|
| Use of string copy function in a condition (`cpp/string-copy-return-value-as-boolean`) | correctness | This rule flags calls to string copy functions used in conditions, where it's likely that a different function was intended to be called. |
| Use of string copy function in a condition (`cpp/string-copy-return-value-as-boolean`) | correctness | This query identifies calls to string copy functions used in conditions, where it's likely that a different function was intended to be called. |
## Changes to existing queries

Просмотреть файл

@ -4,7 +4,7 @@
<qhelp>
<overview>
<p>This rule flags calls to string copy functions used in conditions, either
<p>This query identifies calls to string copy functions used in conditions, either
directly or as part of an equality operator or logical operator. The most
common string copy functions always return their <code>destination</code>
parameter and do not have a return value reserved to indicate an error.
@ -39,7 +39,7 @@ context.</p>
<references>
<li>Microsoft Code Analysis for C/C++: <a href="https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2012/ccf4h9w8(v=vs.110)">C6324</a></li>
<li>Microsoft C library reference: <a href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strcpy-wcscpy-mbscpy">strcpy, wcscpy, _mbscpy</a></li>
<li>US-CERT: <a href="https://www.us-cert.gov/bsi/articles/knowledge/coding-practices/strcpy_s-and-strcat_s">strncpy_s() and strncat_s()</a></li>
<li>US-CERT: <a href="https://www.us-cert.gov/bsi/articles/knowledge/coding-practices/strcpy_s-and-strcat_s">strcpy_s() and strcat_s()</a></li>
</references>
</qhelp>

Просмотреть файл

@ -37,7 +37,7 @@ predicate isStringCopyCastedAsBoolean(FunctionCall func, Expr expr1, string msg)
DataFlow::localFlow(DataFlow::exprNode(func), DataFlow::exprNode(expr1)) and
isBoolean(expr1.getConversion*()) and
isStringComparisonFunction(func.getTarget().getName()) and
msg = "Return value of " + func.getTarget().getName() + " used as Boolean."
msg = "Return value of " + func.getTarget().getName() + " used as a Boolean."
}
predicate isStringCopyUsedInLogicalOperationOrCondition(FunctionCall func, Expr expr1, string msg) {
@ -60,8 +60,7 @@ predicate isStringCopyUsedInLogicalOperationOrCondition(FunctionCall func, Expr
func = ble.getAnOperand()
)
) and
msg = "Return value of " + func.getTarget().getName() +
" used in a logical operation."
msg = "Return value of " + func.getTarget().getName() + " used in a logical operation."
or
// or the string copy function is used directly as the conditional expression
(