LF for .qhelp files too

This commit is contained in:
Dave Bartolomeo
2018-08-26 21:12:51 -07:00
parent dfb082e34f
commit 2af82d9485
4 changed files with 132 additions and 131 deletions

View File

@@ -1,2 +1,2 @@
[*.{ql,qll,qlref,dbscheme,}] [*.{ql,qll,qlref,dbscheme,qhelp}]
end_of_line = lf end_of_line = lf

1
.gitattributes vendored
View File

@@ -14,3 +14,4 @@
*.qll eol=lf *.qll eol=lf
*.qlref eol=lf *.qlref eol=lf
*.dbscheme eol=lf *.dbscheme eol=lf
*.qhelp eol=lf

View File

@@ -1,41 +1,41 @@
<!DOCTYPE qhelp PUBLIC <!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN" "-//Semmle//qhelp//EN"
"qhelp.dtd"> "qhelp.dtd">
<qhelp> <qhelp>
<overview> <overview>
<p>In a loop condition, comparison of a value of a narrow type with a value of a wide type may <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 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> the narrower value may overflow. This can lead to an infinite loop.</p>
</overview> </overview>
<recommendation> <recommendation>
<p>Change the types of the compared values so that the value on the narrower side of the <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> comparison is at least as wide as the value it is being compared with.</p>
</recommendation> </recommendation>
<example> <example>
<p>In this example, <code>bytes_received</code> is compared against <code>max_get</code> in a <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>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>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 <code>INT16_MAX</code>, the loop condition is always <code>true</code>, so the loop never
terminates.</p> terminates.</p>
<p>This problem is avoided in the 'GOOD' case because <code>bytes_received2</code> is an <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> <code>int32_t</code>, which is as wide as the type of <code>max_get</code>.</p>
<sample src="ComparisonWithWiderType.c" /> <sample src="ComparisonWithWiderType.c" />
</example> </example>
<references> <references>
<li> <li>
<a href="https://docs.microsoft.com/en-us/cpp/cpp/data-type-ranges">Data type ranges</a> <a href="https://docs.microsoft.com/en-us/cpp/cpp/data-type-ranges">Data type ranges</a>
</li> </li>
<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> <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> </li>
</references> </references>
</qhelp> </qhelp>

View File

@@ -1,90 +1,90 @@
<!DOCTYPE qhelp PUBLIC <!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN" "-//Semmle//qhelp//EN"
"qhelp.dtd"> "qhelp.dtd">
<qhelp> <qhelp>
<overview> <overview>
<p>There are a number of Boolean expression patterns that can easily be rewritten <p>There are a number of Boolean expression patterns that can easily be rewritten
to make them simpler. to make them simpler.
Boolean expressions involving comparisons with Boolean literals, Boolean expressions involving comparisons with Boolean literals,
ternary conditionals with a Boolean literal as one of the results, ternary conditionals with a Boolean literal as one of the results,
double negations, or negated comparisons can all be changed to double negations, or negated comparisons can all be changed to
equivalent and simpler expressions.</p> equivalent and simpler expressions.</p>
</overview> </overview>
<recommendation> <recommendation>
<p>If <code>A</code> and <code>B</code> are expressions of Boolean type, you can <p>If <code>A</code> and <code>B</code> are expressions of Boolean type, you can
simplify them using the rewrites shown below.</p> simplify them using the rewrites shown below.</p>
<table><tbody> <table><tbody>
<tr><th>Expression</th><th></th><th>Simplified expression</th></tr> <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 == 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 == 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</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 ? 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 &amp;&amp; B</code></td></tr> <tr><td><code>A ? B : false</code></td><td></td><td><code>A &amp;&amp; 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 ? 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 &amp;&amp; B</code></td></tr> <tr><td><code>A ? false : B</code></td><td></td><td><code>!A &amp;&amp; B</code></td></tr>
<tr><td><code>A ? true : false</code></td><td></td><td><code>A</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 ? 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</code></td><td></td><td><code>A</code></td></tr>
<tr><td><code>A &amp;&amp; true</code></td><td></td><td><code>A</code></td></tr> <tr><td><code>A &amp;&amp; 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>
</tbody></table> </tbody></table>
<p>Some expressions always yield a constant value. If the side-effect in <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. <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> Otherwise, replace the expression with the constant value as shown below.</p>
<table><tbody> <table><tbody>
<tr><th>Expression</th><th></th><th>Value</th></tr> <tr><th>Expression</th><th></th><th>Value</th></tr>
<tr><td><code>A &amp;&amp; false</code></td><td></td><td><code>false</code></td></tr> <tr><td><code>A &amp;&amp; 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</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 ? 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> <tr><td><code>A ? false : false</code></td><td></td><td><code>false</code></td></tr>
</tbody></table> </tbody></table>
<p>In addition to the rewrites above, negated comparisons can also be simplified in the following way:</p> <p>In addition to the rewrites above, negated comparisons can also be simplified in the following way:</p>
<table><tbody> <table><tbody>
<tr><th>Expression</th><th></th><th>Simplified expression</th></tr> <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 &lt; B)</code></td><td></td><td><code>A >= B</code></td></tr> <tr><td><code>!(A &lt; B)</code></td><td></td><td><code>A >= B</code></td></tr>
<tr><td><code>!(A > B)</code></td><td></td><td><code>A &lt;= B</code></td></tr> <tr><td><code>!(A > B)</code></td><td></td><td><code>A &lt;= B</code></td></tr>
<tr><td><code>!(A &lt;= B)</code></td><td></td><td><code>A > B</code></td></tr> <tr><td><code>!(A &lt;= B)</code></td><td></td><td><code>A > B</code></td></tr>
<tr><td><code>!(A >= B)</code></td><td></td><td><code>A &lt; B</code></td></tr> <tr><td><code>!(A >= B)</code></td><td></td><td><code>A &lt; B</code></td></tr>
</tbody></table> </tbody></table>
</recommendation> </recommendation>
<example> <example>
<p> <p>
In the following example, the properties <code>Espresso</code>, <code>Latte</code>, and <code>Grande</code> 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. are written in a complex way and can be simplified.
</p> </p>
<sample src="SimplifyBoolExprBad.cs" /> <sample src="SimplifyBoolExprBad.cs" />
<p>The code below shows the same logic expressed in a simpler and more readable way.</p> <p>The code below shows the same logic expressed in a simpler and more readable way.</p>
<sample src="SimplifyBoolExprGood.cs" /> <sample src="SimplifyBoolExprGood.cs" />
</example> </example>
<references> <references>
<li> <li>
Microsoft C# Reference: 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/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/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/not-equal-operator">!= Operator</a>,
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-and-operator">&amp;&amp; Operator</a>, <a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-and-operator">&amp;&amp; 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-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/conditional-operator">?: Operator</a>,
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/less-than-operator">&lt; Operator</a>. <a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/less-than-operator">&lt; Operator</a>.
</li> </li>
</references> </references>
</qhelp> </qhelp>