mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
LF for .qhelp files too
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
[*.{ql,qll,qlref,dbscheme,}]
|
||||
[*.{ql,qll,qlref,dbscheme,qhelp}]
|
||||
end_of_line = lf
|
||||
|
||||
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -14,3 +14,4 @@
|
||||
*.qll eol=lf
|
||||
*.qlref eol=lf
|
||||
*.dbscheme eol=lf
|
||||
*.qhelp eol=lf
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
<overview>
|
||||
<p>In a loop condition, comparison of a value of a narrow type with a value of a wide type may
|
||||
result in unexpected behavior if the wider value is sufficiently large (or small). This is because
|
||||
the narrower value may overflow. This can lead to an infinite loop.</p>
|
||||
|
||||
</overview>
|
||||
<recommendation>
|
||||
|
||||
<p>Change the types of the compared values so that the value on the narrower side of the
|
||||
comparison is at least as wide as the value it is being compared with.</p>
|
||||
|
||||
</recommendation>
|
||||
<example>
|
||||
|
||||
<p>In this example, <code>bytes_received</code> is compared against <code>max_get</code> in a
|
||||
<code>while</code> loop. However, <code>bytes_received</code> is an <code>int16_t</code>, and
|
||||
<code>max_get</code> is an <code>int32_t</code>. Because <code>max_get</code> is larger than
|
||||
<code>INT16_MAX</code>, the loop condition is always <code>true</code>, so the loop never
|
||||
terminates.</p>
|
||||
|
||||
<p>This problem is avoided in the 'GOOD' case because <code>bytes_received2</code> is an
|
||||
<code>int32_t</code>, which is as wide as the type of <code>max_get</code>.</p>
|
||||
|
||||
<sample src="ComparisonWithWiderType.c" />
|
||||
|
||||
</example>
|
||||
|
||||
<references>
|
||||
<li>
|
||||
<a href="https://docs.microsoft.com/en-us/cpp/cpp/data-type-ranges">Data type ranges</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="https://wiki.sei.cmu.edu/confluence/display/c/INT18-C.+Evaluate+integer+expressions+in+a+larger+size+before+comparing+or+assigning+to+that+size">INT18-C. Evaluate integer expressions in a larger size before comparing or assigning to that size </a>
|
||||
</li>
|
||||
</references>
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
<overview>
|
||||
<p>In a loop condition, comparison of a value of a narrow type with a value of a wide type may
|
||||
result in unexpected behavior if the wider value is sufficiently large (or small). This is because
|
||||
the narrower value may overflow. This can lead to an infinite loop.</p>
|
||||
|
||||
</overview>
|
||||
<recommendation>
|
||||
|
||||
<p>Change the types of the compared values so that the value on the narrower side of the
|
||||
comparison is at least as wide as the value it is being compared with.</p>
|
||||
|
||||
</recommendation>
|
||||
<example>
|
||||
|
||||
<p>In this example, <code>bytes_received</code> is compared against <code>max_get</code> in a
|
||||
<code>while</code> loop. However, <code>bytes_received</code> is an <code>int16_t</code>, and
|
||||
<code>max_get</code> is an <code>int32_t</code>. Because <code>max_get</code> is larger than
|
||||
<code>INT16_MAX</code>, the loop condition is always <code>true</code>, so the loop never
|
||||
terminates.</p>
|
||||
|
||||
<p>This problem is avoided in the 'GOOD' case because <code>bytes_received2</code> is an
|
||||
<code>int32_t</code>, which is as wide as the type of <code>max_get</code>.</p>
|
||||
|
||||
<sample src="ComparisonWithWiderType.c" />
|
||||
|
||||
</example>
|
||||
|
||||
<references>
|
||||
<li>
|
||||
<a href="https://docs.microsoft.com/en-us/cpp/cpp/data-type-ranges">Data type ranges</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="https://wiki.sei.cmu.edu/confluence/display/c/INT18-C.+Evaluate+integer+expressions+in+a+larger+size+before+comparing+or+assigning+to+that+size">INT18-C. Evaluate integer expressions in a larger size before comparing or assigning to that size </a>
|
||||
</li>
|
||||
</references>
|
||||
</qhelp>
|
||||
@@ -1,90 +1,90 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
|
||||
<overview>
|
||||
<p>There are a number of Boolean expression patterns that can easily be rewritten
|
||||
to make them simpler.
|
||||
Boolean expressions involving comparisons with Boolean literals,
|
||||
ternary conditionals with a Boolean literal as one of the results,
|
||||
double negations, or negated comparisons can all be changed to
|
||||
equivalent and simpler expressions.</p>
|
||||
</overview>
|
||||
|
||||
<recommendation>
|
||||
<p>If <code>A</code> and <code>B</code> are expressions of Boolean type, you can
|
||||
simplify them using the rewrites shown below.</p>
|
||||
|
||||
<table><tbody>
|
||||
<tr><th>Expression</th><th></th><th>Simplified expression</th></tr>
|
||||
<tr><td><code>A == true</code></td><td></td><td><code>A</code></td></tr>
|
||||
<tr><td><code>A != false</code></td><td></td><td><code>A</code></td></tr>
|
||||
<tr><td><code>A == false</code></td><td></td><td><code>!A</code></td></tr>
|
||||
<tr><td><code>A != true</code></td><td></td><td><code>!A</code></td></tr>
|
||||
<tr><td><code>A ? true : B</code></td><td></td><td><code>A || B</code></td></tr>
|
||||
<tr><td><code>A ? B : false</code></td><td></td><td><code>A && B</code></td></tr>
|
||||
<tr><td><code>A ? B : true</code></td><td></td><td><code>!A || B</code></td></tr>
|
||||
<tr><td><code>A ? false : B</code></td><td></td><td><code>!A && B</code></td></tr>
|
||||
<tr><td><code>A ? true : false</code></td><td></td><td><code>A</code></td></tr>
|
||||
<tr><td><code>A ? false : true</code></td><td></td><td><code>!A</code></td></tr>
|
||||
<tr><td><code>!!A</code></td><td></td><td><code>A</code></td></tr>
|
||||
<tr><td><code>A && true</code></td><td></td><td><code>A</code></td></tr>
|
||||
<tr><td><code>A || false</code></td><td></td><td><code>A</code></td></tr>
|
||||
</tbody></table>
|
||||
|
||||
<p>Some expressions always yield a constant value. If the side-effect in
|
||||
<code>A</code> is intended, consider restructuring the code to make this more clear.
|
||||
Otherwise, replace the expression with the constant value as shown below.</p>
|
||||
|
||||
<table><tbody>
|
||||
<tr><th>Expression</th><th></th><th>Value</th></tr>
|
||||
<tr><td><code>A && false</code></td><td></td><td><code>false</code></td></tr>
|
||||
<tr><td><code>A || true</code></td><td></td><td><code>true</code></td></tr>
|
||||
<tr><td><code>A ? true : true</code></td><td></td><td><code>true</code></td></tr>
|
||||
<tr><td><code>A ? false : false</code></td><td></td><td><code>false</code></td></tr>
|
||||
</tbody></table>
|
||||
|
||||
<p>In addition to the rewrites above, negated comparisons can also be simplified in the following way:</p>
|
||||
|
||||
<table><tbody>
|
||||
<tr><th>Expression</th><th></th><th>Simplified expression</th></tr>
|
||||
<tr><td><code>!(A == B)</code></td><td></td><td><code>A != B</code></td></tr>
|
||||
<tr><td><code>!(A != B)</code></td><td></td><td><code>A == B</code></td></tr>
|
||||
<tr><td><code>!(A < B)</code></td><td></td><td><code>A >= B</code></td></tr>
|
||||
<tr><td><code>!(A > B)</code></td><td></td><td><code>A <= B</code></td></tr>
|
||||
<tr><td><code>!(A <= B)</code></td><td></td><td><code>A > B</code></td></tr>
|
||||
<tr><td><code>!(A >= B)</code></td><td></td><td><code>A < B</code></td></tr>
|
||||
</tbody></table>
|
||||
|
||||
</recommendation>
|
||||
|
||||
<example>
|
||||
<p>
|
||||
In the following example, the properties <code>Espresso</code>, <code>Latte</code>, and <code>Grande</code>
|
||||
are written in a complex way and can be simplified.
|
||||
</p>
|
||||
|
||||
<sample src="SimplifyBoolExprBad.cs" />
|
||||
|
||||
<p>The code below shows the same logic expressed in a simpler and more readable way.</p>
|
||||
|
||||
<sample src="SimplifyBoolExprGood.cs" />
|
||||
</example>
|
||||
|
||||
<references>
|
||||
|
||||
<li>
|
||||
Microsoft C# Reference:
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/logical-negation-operator">! Operator</a>,
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/equality-comparison-operator">== Operator</a>,
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/not-equal-operator">!= Operator</a>,
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-and-operator">&& Operator</a>,
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-or-operator">|| Operator</a>,
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-operator">?: Operator</a>,
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/less-than-operator">< Operator</a>.
|
||||
</li>
|
||||
|
||||
</references>
|
||||
|
||||
</qhelp>
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
|
||||
<overview>
|
||||
<p>There are a number of Boolean expression patterns that can easily be rewritten
|
||||
to make them simpler.
|
||||
Boolean expressions involving comparisons with Boolean literals,
|
||||
ternary conditionals with a Boolean literal as one of the results,
|
||||
double negations, or negated comparisons can all be changed to
|
||||
equivalent and simpler expressions.</p>
|
||||
</overview>
|
||||
|
||||
<recommendation>
|
||||
<p>If <code>A</code> and <code>B</code> are expressions of Boolean type, you can
|
||||
simplify them using the rewrites shown below.</p>
|
||||
|
||||
<table><tbody>
|
||||
<tr><th>Expression</th><th></th><th>Simplified expression</th></tr>
|
||||
<tr><td><code>A == true</code></td><td></td><td><code>A</code></td></tr>
|
||||
<tr><td><code>A != false</code></td><td></td><td><code>A</code></td></tr>
|
||||
<tr><td><code>A == false</code></td><td></td><td><code>!A</code></td></tr>
|
||||
<tr><td><code>A != true</code></td><td></td><td><code>!A</code></td></tr>
|
||||
<tr><td><code>A ? true : B</code></td><td></td><td><code>A || B</code></td></tr>
|
||||
<tr><td><code>A ? B : false</code></td><td></td><td><code>A && B</code></td></tr>
|
||||
<tr><td><code>A ? B : true</code></td><td></td><td><code>!A || B</code></td></tr>
|
||||
<tr><td><code>A ? false : B</code></td><td></td><td><code>!A && B</code></td></tr>
|
||||
<tr><td><code>A ? true : false</code></td><td></td><td><code>A</code></td></tr>
|
||||
<tr><td><code>A ? false : true</code></td><td></td><td><code>!A</code></td></tr>
|
||||
<tr><td><code>!!A</code></td><td></td><td><code>A</code></td></tr>
|
||||
<tr><td><code>A && true</code></td><td></td><td><code>A</code></td></tr>
|
||||
<tr><td><code>A || false</code></td><td></td><td><code>A</code></td></tr>
|
||||
</tbody></table>
|
||||
|
||||
<p>Some expressions always yield a constant value. If the side-effect in
|
||||
<code>A</code> is intended, consider restructuring the code to make this more clear.
|
||||
Otherwise, replace the expression with the constant value as shown below.</p>
|
||||
|
||||
<table><tbody>
|
||||
<tr><th>Expression</th><th></th><th>Value</th></tr>
|
||||
<tr><td><code>A && false</code></td><td></td><td><code>false</code></td></tr>
|
||||
<tr><td><code>A || true</code></td><td></td><td><code>true</code></td></tr>
|
||||
<tr><td><code>A ? true : true</code></td><td></td><td><code>true</code></td></tr>
|
||||
<tr><td><code>A ? false : false</code></td><td></td><td><code>false</code></td></tr>
|
||||
</tbody></table>
|
||||
|
||||
<p>In addition to the rewrites above, negated comparisons can also be simplified in the following way:</p>
|
||||
|
||||
<table><tbody>
|
||||
<tr><th>Expression</th><th></th><th>Simplified expression</th></tr>
|
||||
<tr><td><code>!(A == B)</code></td><td></td><td><code>A != B</code></td></tr>
|
||||
<tr><td><code>!(A != B)</code></td><td></td><td><code>A == B</code></td></tr>
|
||||
<tr><td><code>!(A < B)</code></td><td></td><td><code>A >= B</code></td></tr>
|
||||
<tr><td><code>!(A > B)</code></td><td></td><td><code>A <= B</code></td></tr>
|
||||
<tr><td><code>!(A <= B)</code></td><td></td><td><code>A > B</code></td></tr>
|
||||
<tr><td><code>!(A >= B)</code></td><td></td><td><code>A < B</code></td></tr>
|
||||
</tbody></table>
|
||||
|
||||
</recommendation>
|
||||
|
||||
<example>
|
||||
<p>
|
||||
In the following example, the properties <code>Espresso</code>, <code>Latte</code>, and <code>Grande</code>
|
||||
are written in a complex way and can be simplified.
|
||||
</p>
|
||||
|
||||
<sample src="SimplifyBoolExprBad.cs" />
|
||||
|
||||
<p>The code below shows the same logic expressed in a simpler and more readable way.</p>
|
||||
|
||||
<sample src="SimplifyBoolExprGood.cs" />
|
||||
</example>
|
||||
|
||||
<references>
|
||||
|
||||
<li>
|
||||
Microsoft C# Reference:
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/logical-negation-operator">! Operator</a>,
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/equality-comparison-operator">== Operator</a>,
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/not-equal-operator">!= Operator</a>,
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-and-operator">&& Operator</a>,
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-or-operator">|| Operator</a>,
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-operator">?: Operator</a>,
|
||||
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/less-than-operator">< Operator</a>.
|
||||
</li>
|
||||
|
||||
</references>
|
||||
|
||||
</qhelp>
|
||||
|
||||
Reference in New Issue
Block a user