diff --git a/.editorconfig b/.editorconfig index 5e3cc84e1ff..476ae898a0f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,2 +1,2 @@ -[*.{ql,qll,qlref,dbscheme,}] +[*.{ql,qll,qlref,dbscheme,qhelp}] end_of_line = lf diff --git a/.gitattributes b/.gitattributes index 04a0ee05cf8..a6c5703f96b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14,3 +14,4 @@ *.qll eol=lf *.qlref eol=lf *.dbscheme eol=lf +*.qhelp eol=lf diff --git a/cpp/ql/src/Security/CWE/CWE-190/ComparisonWithWiderType.qhelp b/cpp/ql/src/Security/CWE/CWE-190/ComparisonWithWiderType.qhelp index 4506eb053ce..78f956c939a 100644 --- a/cpp/ql/src/Security/CWE/CWE-190/ComparisonWithWiderType.qhelp +++ b/cpp/ql/src/Security/CWE/CWE-190/ComparisonWithWiderType.qhelp @@ -1,41 +1,41 @@ - - - -

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.

- -
- - -

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.

- -
- - -

In this example, bytes_received is compared against max_get in a -while loop. However, bytes_received is an int16_t, and -max_get is an int32_t. Because max_get is larger than -INT16_MAX, the loop condition is always true, so the loop never -terminates.

- -

This problem is avoided in the 'GOOD' case because bytes_received2 is an -int32_t, which is as wide as the type of max_get.

- - - -
- - -
  • - Data type ranges -
  • - -
  • - INT18-C. Evaluate integer expressions in a larger size before comparing or assigning to that size -
  • -
    + + + +

    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.

    + +
    + + +

    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.

    + +
    + + +

    In this example, bytes_received is compared against max_get in a +while loop. However, bytes_received is an int16_t, and +max_get is an int32_t. Because max_get is larger than +INT16_MAX, the loop condition is always true, so the loop never +terminates.

    + +

    This problem is avoided in the 'GOOD' case because bytes_received2 is an +int32_t, which is as wide as the type of max_get.

    + + + +
    + + +
  • + Data type ranges +
  • + +
  • + INT18-C. Evaluate integer expressions in a larger size before comparing or assigning to that size +
  • +
    \ No newline at end of file diff --git a/csharp/ql/src/Language Abuse/SimplifyBoolExpr.qhelp b/csharp/ql/src/Language Abuse/SimplifyBoolExpr.qhelp index f5ba2aceb80..bacd2164206 100644 --- a/csharp/ql/src/Language Abuse/SimplifyBoolExpr.qhelp +++ b/csharp/ql/src/Language Abuse/SimplifyBoolExpr.qhelp @@ -1,90 +1,90 @@ - - - - -

    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.

    -
    - - -

    If A and B are expressions of Boolean type, you can -simplify them using the rewrites shown below.

    - - - - - - - - - - - - - - - - -
    ExpressionSimplified expression
    A == trueA
    A != falseA
    A == false!A
    A != true!A
    A ? true : BA || B
    A ? B : falseA && B
    A ? B : true!A || B
    A ? false : B!A && B
    A ? true : falseA
    A ? false : true!A
    !!AA
    A && trueA
    A || falseA
    - -

    Some expressions always yield a constant value. If the side-effect in -A is intended, consider restructuring the code to make this more clear. -Otherwise, replace the expression with the constant value as shown below.

    - - - - - - - -
    ExpressionValue
    A && falsefalse
    A || truetrue
    A ? true : truetrue
    A ? false : falsefalse
    - -

    In addition to the rewrites above, negated comparisons can also be simplified in the following way:

    - - - - - - - - - -
    ExpressionSimplified expression
    !(A == B)A != B
    !(A != B)A == B
    !(A < B)A >= B
    !(A > B)A <= B
    !(A <= B)A > B
    !(A >= B)A < B
    - -
    - - -

    -In the following example, the properties Espresso, Latte, and Grande -are written in a complex way and can be simplified. -

    - - - -

    The code below shows the same logic expressed in a simpler and more readable way.

    - - -
    - - - -
  • -Microsoft C# Reference: -! Operator, -== Operator, -!= Operator, -&& Operator, -|| Operator, -?: Operator, -< Operator. -
  • - -
    - -
    + + + + +

    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.

    +
    + + +

    If A and B are expressions of Boolean type, you can +simplify them using the rewrites shown below.

    + + + + + + + + + + + + + + + + +
    ExpressionSimplified expression
    A == trueA
    A != falseA
    A == false!A
    A != true!A
    A ? true : BA || B
    A ? B : falseA && B
    A ? B : true!A || B
    A ? false : B!A && B
    A ? true : falseA
    A ? false : true!A
    !!AA
    A && trueA
    A || falseA
    + +

    Some expressions always yield a constant value. If the side-effect in +A is intended, consider restructuring the code to make this more clear. +Otherwise, replace the expression with the constant value as shown below.

    + + + + + + + +
    ExpressionValue
    A && falsefalse
    A || truetrue
    A ? true : truetrue
    A ? false : falsefalse
    + +

    In addition to the rewrites above, negated comparisons can also be simplified in the following way:

    + + + + + + + + + +
    ExpressionSimplified expression
    !(A == B)A != B
    !(A != B)A == B
    !(A < B)A >= B
    !(A > B)A <= B
    !(A <= B)A > B
    !(A >= B)A < B
    + +
    + + +

    +In the following example, the properties Espresso, Latte, and Grande +are written in a complex way and can be simplified. +

    + + + +

    The code below shows the same logic expressed in a simpler and more readable way.

    + + +
    + + + +
  • +Microsoft C# Reference: +! Operator, +== Operator, +!= Operator, +&& Operator, +|| Operator, +?: Operator, +< Operator. +
  • + +
    + +