Skip to content

Commit 6ff1c99

Browse files
author
james
committed
docs: a few content updates
1 parent d3eb533 commit 6ff1c99

9 files changed

Lines changed: 30 additions & 37 deletions

docs/language/learn-ql/cpp/conversions-classes.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ You can use the standard CodeQL libraries for C and C++ to detect when the type
66
Conversions
77
-----------
88

9-
Let us take a look at the ``Conversion`` class in the standard library:
9+
In C and C++, conversions change the type of an expression. They may be implicit conversions generated by the compiler, or explicit conversions requested by the user.
10+
11+
Let's take a look at the `Conversion <https://help.semmle.com/qldoc/cpp/semmle/code/cpp/exprs/Cast.qll/type.Cast$Conversion.html>`__ class in the standard library:
1012

1113
- ``Expr``
1214

@@ -22,8 +24,6 @@ Let us take a look at the ``Conversion`` class in the standard library:
2224
- ``ArrayToPointerConversion``
2325
- ``VirtualMemberToFunctionPointerConversion``
2426

25-
All conversions change the type of an expression. They may be implicit conversions (generated by the compiler) or explicit conversions (requested by the user).
26-
2727
Exploring the subexpressions of an assignment
2828
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2929

@@ -218,7 +218,7 @@ Our last change is to use ``Function.isVirtual()`` to find cases where the base
218218

219219
That completes the query.
220220

221-
There is a similar built-in LGTM `query <https://lgtm.com/rules/2158670642/>`__ that finds classes in a C/C++ project with virtual functions but no virtual destructor. You can take a look at the code for this query by clicking **Open in query console** at the top of that page.
221+
There is a similar built-in `query <https://lgtm.com/rules/2158670642/>`__ on LGTM.com that finds classes in a C/C++ project with virtual functions but no virtual destructor. You can take a look at the code for this query by clicking **Open in query console** at the top of that page.
222222

223223
What next?
224224
----------

docs/language/learn-ql/cpp/dataflow.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Analyzing data flow in C and C++
22
================================
33

4-
You can use data-flow analysis to track the flow of potentially malicious or insecure data that can cause vulnerabilities in your code base.
4+
You can use data-flow analysis to track the flow of potentially malicious or insecure data that can cause vulnerabilities in your codebase.
55

6-
This topic describes how data flow analysis is implemented in the CodeQL libraries for C/C++ and includes examples to help you write your own data flow queries.
7-
The following sections describe how to utilize the libraries for local data flow, global data flow, and taint tracking.
6+
About data flow
7+
---------------
88

9-
For a more general introduction to modeling data flow, see :doc:`Introduction to data flow analysis with CodeQL <../intro-to-data-flow>`.
9+
Data flow analysis computes the possible values that a variable can hold at various points in a program, determining how those values propagate through the program, and where they are used. In CodeQL, you can model both local data flow and global data flow. For more background information, see :doc:`Introduction to data flow analysis with CodeQL <../intro-to-data-flow>`.
1010

1111
Local data flow
1212
---------------

docs/language/learn-ql/cpp/expressions-types.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ Expressions, types, and statements in C and C++
33

44
You can use CodeQL to explore expressions, types, and statements in C and C++ code to find, for example, incorrect assignments.
55

6-
This topic contains worked examples of how to write queries using the standard CodeQL library classes for C/C++ expressions, types, and statements.
7-
8-
Expressions and types
9-
---------------------
6+
Expressions and types in CodeQL
7+
-------------------------------
108

119
Each part of an expression in C becomes an instance of the ``Expr`` class. For example, the C code ``x = x + 1`` becomes an ``AssignExpr``, an ``AddExpr``, two instances of ``VariableAccess`` and a ``Literal``. All of these CodeQL classes extend ``Expr``.
1210

@@ -33,7 +31,7 @@ It is also worth noting that the query above would find this C code:
3331
3432
yPtr = NULL;
3533
36-
This is because the database contains a representation of the code base after the preprocessor transforms have run (for more information, see `Database generation <https://lgtm.com/help/lgtm/generate-database>`__). This means that any macro invocations, such as the ``NULL`` define used here, are expanded during the creation of the database. If you want to write queries about macros then there are some special library classes that have been designed specifically for this purpose (for example, the ``Macro``, ``MacroInvocation`` classes and predicates like ``Element.isInMacroExpansion()``). In this case, it is good that macros are expanded, but we do not want to find assignments to pointers.
34+
This is because the database contains a representation of the code base after the preprocessor transforms have run. This means that any macro invocations, such as the ``NULL`` define used here, are expanded during the creation of the database. If you want to write queries about macros then there are some special library classes that have been designed specifically for this purpose (for example, the ``Macro``, ``MacroInvocation`` classes and predicates like ``Element.isInMacroExpansion()``). In this case, it is good that macros are expanded, but we do not want to find assignments to pointers. For more information, see `Database generation <https://lgtm.com/help/lgtm/generate-database>`__ on LGTM.com.
3735

3836
Finding assignments of 0 to an integer
3937
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -60,8 +58,8 @@ This checks that the left side of the assignment has a type that is some kind of
6058
6159
i = 0;
6260
63-
Statements
64-
----------
61+
Statements in CodeQL
62+
--------------------
6563

6664
We can refine the query further using statements. In this case we use the class ``ForStmt``:
6765

docs/language/learn-ql/cpp/guards.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Using the guards library in C and C++
33

44
You can use the CodeQL guards library to identify conditional expressions that control the execution of other code in C and C++ codebases.
55

6-
Overview
7-
--------
6+
About the guards library
7+
------------------------
88

99
The guards library (defined in ``semmle.code.cpp.controlflow.Guards``) provides a class `GuardCondition <https://help.semmle.com/qldoc/cpp/semmle/code/cpp/controlflow/Guards.qll/type.Guards$GuardCondition.html>`__ representing Boolean values that are used to make control flow decisions.
1010
A ``GuardCondition`` is considered to guard a basic block if the block can only be reached if the ``GuardCondition`` is evaluated a certain way. For instance, in the following code, ``x < 10`` is a ``GuardCondition``, and it guards all the code before the return statement.
@@ -22,7 +22,7 @@ A ``GuardCondition`` is considered to guard a basic block if the block can only
2222
2323
2424
The ``controls`` predicate
25-
------------------------------------------------
25+
--------------------------
2626

2727
The ``controls`` predicate helps determine which blocks are only run when the ``GuardCondition`` evaluates a certain way. ``guard.controls(block, testIsTrue)`` holds if ``block`` is only entered if the value of this condition is ``testIsTrue``.
2828

docs/language/learn-ql/cpp/introduce-libraries-cpp.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ CodeQL libraries for C and C++
33

44
Explore the standard CodeQL libraries for C and C++.
55

6-
Overview
7-
--------
6+
About the CodeQL libraries for C and C++
7+
----------------------------------------
88

99
There is an extensive library for analyzing CodeQL databases extracted from C/C++ projects. The classes in this library present the data from a database in an object-oriented form and provide abstractions and predicates to help you with common analysis tasks.
1010
The library is implemented as a set of QL modules, that is, files with the extension ``.qll``. The module ``cpp.qll`` imports all the core C/C++ library modules, so you can include the complete library by beginning your query with:
@@ -19,7 +19,7 @@ The rest of this topic summarizes the available CodeQL classes and corresponding
1919

2020
You can find related classes and features using the query console's auto-complete feature. You can also press *F3* to jump to the definition of any element. Library files are opened in new tabs in the console.
2121

22-
Summary of the library classes
22+
Commonly-used library classes
2323
------------------------------
2424

2525
The most commonly used standard library classes are listed below. The listing is broken down by functionality. Each library class is annotated with a C/C++ construct it corresponds to.

docs/language/learn-ql/cpp/private-field-initialization.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ You can improve the results generated by a CodeQL query by adding conditions to
66
Overview
77
--------
88

9-
This topic describes how a C++ query was developed. The example introduces recursive predicates and demonstrates the typical workflow used to refine a query. For a full overview of the topics available for learning to write queries for C/C++ code, see :doc:`CodeQL for C/C++ <ql-for-cpp>`.
9+
This topic describes how a C++ query was developed. The example introduces recursive predicates and demonstrates the typical workflow used to refine a query. For a full overview of the topics available for learning to write queries for C/C++ code, see :doc:`CodeQL for C and C++ <ql-for-cpp>`.
1010

11-
Problem—finding every private field and checking for initialization
12-
-------------------------------------------------------------------
11+
Finding every private field and checking for initialization
12+
-----------------------------------------------------------
1313

1414
Writing a query to check if a constructor initializes all private fields seems like a simple problem, but there are several edge cases to account for.
1515

@@ -102,7 +102,7 @@ You may also wish to consider methods called by constructors that assign to the
102102
int m_value;
103103
};
104104
105-
This case can be excluded by creating a recursive predicate. The recursive predicate is given a function and a field, then checks whether the function assigns to the field. The predicate runs itself on all the functions called by the function that it has been given. By passing the constructor to this predicate, we can check for assignments of a field in all functions called by the constructor, and then do the same for all functions called by those functions all the way down the tree of function calls (see `Recursion <https://help.semmle.com/QL/ql-handbook/recursion.html>`__ for more information).
105+
This case can be excluded by creating a recursive predicate. The recursive predicate is given a function and a field, then checks whether the function assigns to the field. The predicate runs itself on all the functions called by the function that it has been given. By passing the constructor to this predicate, we can check for assignments of a field in all functions called by the constructor, and then do the same for all functions called by those functions all the way down the tree of function calls. For more information, see `Recursion <https://help.semmle.com/QL/ql-handbook/recursion.html>`__ in the QL language handbook.
106106

107107
.. code-block:: ql
108108
@@ -126,7 +126,7 @@ This case can be excluded by creating a recursive predicate. The recursive predi
126126
Refinement 4—simplifying the query
127127
----------------------------------
128128

129-
Finally we can simplify the query by using the `transitive closure operator <https://help.semmle.com/QL/ql-handbook/recursion.html#transitive-closures>`__. In this final version of the query, ``c.calls*(fun)`` resolves to the set of all functions that are ``c`` itself, are called by ``c``, are called by a function that is called by ``c``, and so on. This eliminates the need to make a new predicate all together.
129+
Finally we can simplify the query by using the transitive closure operator. In this final version of the query, ``c.calls*(fun)`` resolves to the set of all functions that are ``c`` itself, are called by ``c``, are called by a function that is called by ``c``, and so on. This eliminates the need to make a new predicate all together. For more information, see `transitive closures <https://help.semmle.com/QL/ql-handbook/recursion.html#transitive-closures>`__ in the QL language handbook.
130130

131131
.. code-block:: ql
132132

docs/language/learn-ql/cpp/range-analysis.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ Using range analysis for C and C++
33

44
You can use range analysis to determine the upper or lower bounds on an expression, or whether an expression could potentially over or underflow.
55

6-
Overview
7-
--------
8-
9-
Range analysis determines upper and lower bounds for an expression.
6+
About the range analysis library
7+
--------------------------------
108

119
The range analysis library (defined in ``semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis``) provides a set of predicates for determining constant upper and lower bounds on expressions, as well as recognizing integer overflows. For performance, the library performs automatic widening and therefore may not provide the tightest possible bounds.
1210

docs/language/learn-ql/cpp/value-numbering-hash-cons.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ Hash consing and value numbering
33

44
You can use specialized CodeQL libraries to recognize expressions that are syntactically identical or compute the same value at runtime in C and C++ codebases.
55

6-
Overview
7-
--------
6+
About the hash consing and value numbering libraries
7+
----------------------------------------------------
88

99
In C and C++ databases, each node in the abstract syntax tree is represented by a separate object. This allows both analysis and results display to refer to specific appearances of a piece of syntax. However, it is frequently useful to determine whether two expressions are equivalent, either syntactically or semantically.
1010

11-
The `hash consing <https://en.wikipedia.org/wiki/Hash_consing>`__ library (defined in ``semmle.code.cpp.valuenumbering.HashCons``) provides a mechanism for identifying expressions that have the same syntactic structure. The `global value numbering <https://en.wikipedia.org/wiki/Value_numbering>`__ library (defined in ``semmle.code.cpp.valuenumbering.GlobalValueNumbering``) provides a mechanism for identifying expressions that compute the same value at runtime.
12-
13-
Both libraries partition the expressions in each function into equivalence classes represented by objects. Each ``HashCons`` object represents a set of expressions with identical parse trees, while ``GVN`` objects represent sets of expressions that will always compute the same value.
14-
11+
The hash consing library (defined in ``semmle.code.cpp.valuenumbering.HashCons``) provides a mechanism for identifying expressions that have the same syntactic structure. The global value numbering library (defined in ``semmle.code.cpp.valuenumbering.GlobalValueNumbering``) provides a mechanism for identifying expressions that compute the same value at runtime. Both libraries partition the expressions in each function into equivalence classes represented by objects. Each ``HashCons`` object represents a set of expressions with identical parse trees, while ``GVN`` objects represent sets of expressions that will always compute the same value. For more information, see `hash consing <https://en.wikipedia.org/wiki/Hash_consing>`__ and `value numbering <https://en.wikipedia.org/wiki/Value_numbering>`__ on Wikipedia.
1512

1613
Example C code
1714
--------------

docs/language/learn-ql/cpp/zero-space-terminator.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ When you have defined the basic query then you can refine the query to include f
100100
Improving the query using the 'SSA' library
101101
-------------------------------------------
102102

103-
The ``SSA`` library represents variables in `static single assignment <http://en.wikipedia.org/wiki/Static_single_assignment_form>`__ (SSA) form. In this form, each variable is assigned exactly once and every variable is defined before it is used. The use of SSA variables simplifies queries considerably as much of the local data flow analysis has been done for us.
103+
The ``SSA`` library represents variables in static single assignment (SSA) form. In this form, each variable is assigned exactly once and every variable is defined before it is used. The use of SSA variables simplifies queries considerably as much of the local data flow analysis has been done for us. For more information, see `static single assignment <http://en.wikipedia.org/wiki/Static_single_assignment_form>`__ on Wikipedia.
104104

105105
Including examples where the string size is stored before use
106106
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)