Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b060fd1

Browse files
Merge branch 'master' into cpp340a
2 parents e4ce834 + f5d52d0 commit b060fd1

76 files changed

Lines changed: 746 additions & 308 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

change-notes/1.21/analysis-cpp.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
| **Query** | **Expected impact** | **Change** |
1515
|----------------------------|------------------------|------------------------------------------------------------------|
16+
| Dead code due to goto or break statement (`cpp/dead-code-goto`) | Fewer false positive results | Functions containing preprocessor logic are now excluded from this analysis. |
1617
| Mismatching new/free or malloc/delete (`cpp/new-free-mismatch`) | Fewer false positive results | Fixed an issue where functions were being identified as allocation functions inappropriately. Also affects `cpp/new-array-delete-mismatch` and `cpp/new-delete-array-mismatch`. |
1718
| Overflow in uncontrolled allocation size (`cpp/uncontrolled-allocation-size`) | More correct results | This query has been reworked so that it can find a wider variety of results. |
1819
| Memory may not be freed (`cpp/memory-may-not-be-freed`) | More correct results | Support added for more Microsoft-specific allocation functions, including `LocalAlloc`, `GlobalAlloc`, `HeapAlloc` and `CoTaskMemAlloc`. |
@@ -21,5 +22,6 @@
2122
| Comparison result is always the same | Fewer false positive results | The range analysis library is now more conservative about floating point values being possibly `NaN` |
2223
| Wrong type of arguments to formatting function (`cpp/wrong-type-format-argument`) | More correct results and fewer false positive results | This query now more accurately identifies wide and non-wide string/character format arguments on different platforms. Platform detection has also been made more accurate for the purposes of this query. |
2324
| `()`-declared function called with too many arguments (`cpp/futile-params`) | Improved coverage | Query has been generalized to find all cases where the number of arguments exceedes the number of parameters of the function, provided the function is also properly declared/defined elsewhere. |
25+
| Wrong type of arguments to formatting function (`cpp/wrong-type-format-argument`) | Fewer false positive results | Non-standard uses of %L are now understood. |
2426

2527
## Changes to QL libraries

change-notes/1.21/analysis-javascript.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
## General improvements
44

55
* Support for the following frameworks and libraries has been improved:
6+
- [koa](https://github.com/koajs/koa)
67
- [socket.io](http://socket.io)
8+
- [Firebase](https://firebase.google.com/)
79

810
* The security queries now track data flow through Base64 decoders such as the Node.js `Buffer` class, the DOM function `atob`, and a number of npm packages intcluding [`abab`](https://www.npmjs.com/package/abab), [`atob`](https://www.npmjs.com/package/atob), [`btoa`](https://www.npmjs.com/package/btoa), [`base-64`](https://www.npmjs.com/package/base-64), [`js-base64`](https://www.npmjs.com/package/js-base64), [`Base64.js`](https://www.npmjs.com/package/Base64) and [`base64-js`](https://www.npmjs.com/package/base64-js).
911

cpp/ql/src/Architecture/General Class-Level Information/HubClasses.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Hub classes
33
* @description Shows coupling between classes. Large, red, boxes are hub types that depend on many other classes
44
* and are depended on by many other classes.
5-
* @kind treemap
5+
* @kind table
66
* @id cpp/architecture/hub-classes
77
* @treemap.warnOn highValues
88
* @tags maintainability

cpp/ql/src/Critical/DeadCodeGoto.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
import cpp
13+
import semmle.code.cpp.commons.Exclusions
1314

1415
Stmt getNextRealStmt(Block b, int i) {
1516
result = b.getStmt(i + 1) and
@@ -30,4 +31,6 @@ where b.getStmt(i) = js
3031
// the next statement isn't a loop that can be jumped into
3132
and not exists (LabelStmt ls | s.(Loop).getStmt().getAChild*() = ls)
3233
and not exists (SwitchCase sc | s.(Loop).getStmt().getAChild*() = sc)
34+
// no preprocessor logic applies
35+
and not functionContainsPreprocCode(js.getEnclosingFunction())
3336
select js, "This statement makes $@ unreachable.", s, s.toString()

cpp/ql/src/jsf/3.02 Code Size and Complexity/AV Rule 3.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ import cpp
1212
from Function f, int c
1313
where c = f.getMetrics().getCyclomaticComplexity() and
1414
c > 20
15-
select f, c as CyclomaticComplexity,
16-
"AV Rule 3: All functions shall have a cyclomatic complexity number of 20 or less."
15+
select f, "AV Rule 3: All functions shall have a cyclomatic complexity number of 20 or less."

cpp/ql/src/jsf/4.10 Classes/AV Rule 81.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @description The assignment operator shall handle self-assignment correctly.
44
* @kind problem
55
* @id cpp/jsf/av-rule-81
6+
* @precision low
67
* @problem.severity error
78
* @tags correctness
89
* external/jsf
@@ -77,4 +78,4 @@ where hasResource(op.getDeclaringType())
7778
and not exists(op.getASelfEqualityTest())
7879
and not exists(op.getASwapCall())
7980
and exists(op.getADeleteExpr())
80-
select op
81+
select op, "AV Rule 81: The assignment operator shall handle self-assignment correctly."

cpp/ql/src/semmle/code/cpp/ASTSanity.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name AST Sanity Check
33
* @description Performs sanity checks on the Abstract Syntax Tree. This query should have no results.
4-
* @kind problem
4+
* @kind table
55
* @id cpp/ast-sanity-check
66
*/
77

cpp/ql/src/semmle/code/cpp/AutogeneratedFile.qll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ private bindingset[comment] predicate autogeneratedComment(string comment) {
2323

2424
// changes made in this file will be lost
2525
"(changes made in this file will be lost)|" +
26-
27-
// do not edit/modify
26+
27+
// do not edit/modify (not mid-sentence)
2828
"(^ do(n't|nt| not) (hand-?)?(edit|modify))|" +
29-
"(! do(n't|nt| not) (hand-?)?(edit|modify))" and
30-
29+
"(! do(n't|nt| not) (hand-?)?(edit|modify))|" +
30+
31+
// do not edit/modify + generated
32+
"(do(n't|nt| not) (hand-?)?(edit|modify).*generated)|" +
33+
"(generated.*do(n't|nt| not) (hand-?)?(edit|modify))" and
34+
3135
comment.regexpMatch("(?si).*(" +
3236
// replace `generated` with a regexp that also catches things like
3337
// `auto-generated`.

cpp/ql/src/semmle/code/cpp/commons/Exclusions.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,16 @@ predicate functionContainsDisabledCode(Function f) {
5858
)
5959
)
6060
}
61+
62+
/**
63+
* Holds if the function `f` contains code that could be excluded by the preprocessor.
64+
*/
65+
predicate functionContainsPreprocCode(Function f) {
66+
// `f` contains a preprocessor branch
67+
exists(PreprocessorBranchDirective pbd, string file, int pbdStartLine, int fBlockStartLine, int fBlockEndLine |
68+
functionLocation(f, file, fBlockStartLine, fBlockEndLine) and
69+
pbdLocation(pbd, file, pbdStartLine) and
70+
pbdStartLine <= fBlockEndLine and
71+
pbdStartLine >= fBlockStartLine
72+
)
73+
}

cpp/ql/src/semmle/code/cpp/commons/Printf.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,8 @@ class FormatLiteral extends Literal {
572572
((len="hh" and result instanceof IntType)
573573
or (len="h" and result instanceof IntType)
574574
or (len="l" and result = this.getLongType())
575-
or ((len="ll" or len="q")
575+
or ((len="ll" or len="L" or len="q")
576576
and result instanceof LongLongType)
577-
or (len="L" and result instanceof IntType) // doesn't affect integral conversion
578577
or (len="j" and result = this.getIntmax_t())
579578
or ((len="z" or len="Z")
580579
and (result = this.getSize_t() or result = this.getSsize_t()))
@@ -599,9 +598,8 @@ class FormatLiteral extends Literal {
599598
((len="hh" and result instanceof CharType)
600599
or (len="h" and result instanceof ShortType)
601600
or (len="l" and result = this.getLongType())
602-
or ((len="ll" or len="q")
601+
or ((len="ll" or len="L" or len="q")
603602
and result instanceof LongLongType)
604-
or (len="L" and result instanceof IntType) // doesn't affect integral conversion
605603
or (len="j" and result = this.getIntmax_t())
606604
or ((len="z" or len="Z")
607605
and (result = this.getSize_t() or result = this.getSsize_t()))
@@ -622,7 +620,7 @@ class FormatLiteral extends Literal {
622620
*/
623621
FloatingPointType getFloatingPointConversion(int n) {
624622
exists(string len | len = this.getLength(n) and
625-
if len="L" then
623+
if (len="L" or len="ll") then
626624
result instanceof LongDoubleType
627625
else
628626
result instanceof DoubleType)
@@ -638,7 +636,7 @@ class FormatLiteral extends Literal {
638636
(len="hh" and base instanceof CharType)
639637
or (len="h" and base instanceof ShortType)
640638
or (len="l" and base = this.getLongType())
641-
or (len="ll" and base instanceof LongLongType)
639+
or ((len="ll" or len="L") and base instanceof LongLongType)
642640
or (len="q" and base instanceof LongLongType)
643641
)
644642
and base.isSigned() and base = result.getBaseType()

0 commit comments

Comments
 (0)