Skip to content

enable syntax highlighting in C/C++ examples #4429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 140 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
8161383
Update c6011.md
Rastaban Dec 3, 2019
7c492da
Update c26140.md
Rastaban Dec 3, 2019
7d69ad4
Update c26135.md
Rastaban Dec 3, 2019
4999f77
Update c26130.md
Rastaban Dec 3, 2019
f045187
Update c26116.md
Rastaban Dec 3, 2019
63c8ba7
Update c26115.md
Rastaban Dec 3, 2019
c32ff5a
Update c26112.md
Rastaban Dec 3, 2019
37ba468
Update c26111.md
Rastaban Dec 3, 2019
c891861
Update c26110.md
Rastaban Dec 3, 2019
7618188
Update c26105.md
Rastaban Dec 3, 2019
55ee5aa
Update c26101.md
Rastaban Dec 3, 2019
accb25b
Update c26100.md
Rastaban Dec 3, 2019
83c4d0c
Update c28303.md
Rastaban Dec 3, 2019
d91c0c0
Update c28198.md
Rastaban Dec 3, 2019
37514c4
Update c28197.md
Rastaban Dec 3, 2019
a9dc55b
Update c28193.md
Rastaban Dec 3, 2019
0f38044
Update c28183.md
Rastaban Dec 3, 2019
975b02b
Update c28182.md
Rastaban Dec 3, 2019
ee08fe9
Update c28164.md
Rastaban Dec 3, 2019
f323f69
Update c28164.md
Rastaban Dec 3, 2019
c8586fa
Update c28159.md
Rastaban Dec 3, 2019
f98bca0
Update c28138.md
Rastaban Dec 3, 2019
f5c2112
Update c28137.md
Rastaban Dec 3, 2019
2b36fe2
Update c28125.md
Rastaban Dec 3, 2019
d9fb64a
Update c28113.md
Rastaban Dec 3, 2019
ca11d4b
Update c28109.md
Rastaban Dec 3, 2019
7149097
Update c28108.md
Rastaban Dec 3, 2019
4b81d8b
Update c28107.md
Rastaban Dec 3, 2019
1a45afc
Update c28106.md
Rastaban Dec 3, 2019
5b277c1
Update c28105.md
Rastaban Dec 3, 2019
1d34165
Update c28104.md
Rastaban Dec 3, 2019
2102d76
Update c28103.md
Rastaban Dec 3, 2019
3e47d83
Update c6292.md
Rastaban Dec 3, 2019
f0b62c3
Update c6292.md
Rastaban Dec 3, 2019
bb6c7c6
Update c6293.md
Rastaban Dec 3, 2019
63592ee
Update c6294.md
Rastaban Dec 3, 2019
0f19e6e
Update c6295.md
Rastaban Dec 3, 2019
ce3571d
Update c6296.md
Rastaban Dec 3, 2019
5f60330
Update c6297.md
Rastaban Dec 3, 2019
e0fb6e4
Update c6298.md
Rastaban Dec 3, 2019
03e9520
Update c6299.md
Rastaban Dec 3, 2019
6f3e557
Update c6289.md
Rastaban Dec 3, 2019
198f47a
Update c6288.md
Rastaban Dec 3, 2019
e269778
Update c6287.md
Rastaban Dec 3, 2019
5b32539
Update c6286.md
Rastaban Dec 3, 2019
d51aee8
Update c6284.md
Rastaban Dec 3, 2019
a8fc14a
Update c6283.md
Rastaban Dec 3, 2019
5d0f012
Update c6282.md
Rastaban Dec 3, 2019
e50eac6
Update c6281.md
Rastaban Dec 3, 2019
b6f65fc
Update c6277.md
Rastaban Dec 3, 2019
e0ca690
Update c6276.md
Rastaban Dec 3, 2019
37ba620
Update c6274.md
Rastaban Dec 3, 2019
c73a4a6
Update c6273.md
Rastaban Dec 3, 2019
308d6f4
Update c6272.md
Rastaban Dec 3, 2019
bdc7b89
Update c6271.md
Rastaban Dec 3, 2019
99388a3
Update c6270.md
Rastaban Dec 3, 2019
09c5dbd
Update c6269.md
Rastaban Dec 3, 2019
a91c1db
Update c6268.md
Rastaban Dec 3, 2019
d6a4e48
Update c6263.md
Rastaban Dec 3, 2019
cc15658
Update c6260.md
Rastaban Dec 3, 2019
ea35988
Update c6260.md
Rastaban Dec 3, 2019
0fea5ac
Update c6259.md
Rastaban Dec 3, 2019
fbdb108
Update c6255.md
Rastaban Dec 3, 2019
0bc0b46
Update c6250.md
Rastaban Dec 3, 2019
8b0cd8f
Update c6248.md
Rastaban Dec 3, 2019
045541e
Update c6248.md
Rastaban Dec 3, 2019
d743a23
Update c6246.md
Rastaban Dec 3, 2019
6760fe1
Update c6244.md
Rastaban Dec 3, 2019
eeece34
Update c6242.md
Rastaban Dec 3, 2019
b3d695c
Update c6240.md
Rastaban Dec 3, 2019
1763222
Update c6239.md
Rastaban Dec 3, 2019
ae3a1cf
Update c6237.md
Rastaban Dec 3, 2019
66f8214
Update c6236.md
Rastaban Dec 3, 2019
337705f
Update c6235.md
Rastaban Dec 3, 2019
984ef29
Update c6230.md
Rastaban Dec 3, 2019
892fbe2
Update c6225.md
Rastaban Dec 3, 2019
0bbcac4
Update c6221.md
Rastaban Dec 3, 2019
edf51b1
Update c6220.md
Rastaban Dec 3, 2019
3cebed2
Update c6216.md
Rastaban Dec 3, 2019
241a9e6
Update c6215.md
Rastaban Dec 3, 2019
6a36cd7
Update c6201.md
Rastaban Dec 3, 2019
50d3dd0
Update c6200.md
Rastaban Dec 3, 2019
c88d902
Update c6067.md
Rastaban Dec 3, 2019
de20dd9
Update c6066.md
Rastaban Dec 3, 2019
9d288eb
Update c6064.md
Rastaban Dec 3, 2019
75ae7ae
Update c6063.md
Rastaban Dec 3, 2019
8e915f0
Update c6059.md
Rastaban Dec 3, 2019
5860aee
Update c6530.md
Rastaban Dec 3, 2019
d5bbb45
Update c6525.md
Rastaban Dec 3, 2019
615e62b
Update c6522.md
Rastaban Dec 3, 2019
693abe0
Update c6516.md
Rastaban Dec 3, 2019
246735e
Update c6515.md
Rastaban Dec 3, 2019
e8b79f9
Update c6514.md
Rastaban Dec 3, 2019
f8720d8
Update c6513.md
Rastaban Dec 3, 2019
c4cb39c
Update c6511.md
Rastaban Dec 3, 2019
739a62d
Update c6510.md
Rastaban Dec 3, 2019
3174b53
Update c6508.md
Rastaban Dec 3, 2019
18c50c7
Update c6501.md
Rastaban Dec 3, 2019
fce5ea4
Update c6500.md
Rastaban Dec 3, 2019
81bceaf
Update c6412.md
Rastaban Dec 3, 2019
7014ea4
Update c6411.md
Rastaban Dec 3, 2019
bb8159a
Update c6401.md
Rastaban Dec 3, 2019
14c34f8
Update c6401.md
Rastaban Dec 3, 2019
7af0c20
Update c6400.md
Rastaban Dec 3, 2019
79ef001
Update c6386.md
Rastaban Dec 3, 2019
f9c30ff
Update c6386.md
Rastaban Dec 3, 2019
2d32212
Update c6385.md
Rastaban Dec 3, 2019
cd97000
Update c6384.md
Rastaban Dec 3, 2019
00310b7
Update c6384.md
Rastaban Dec 3, 2019
daa696d
Update c6383.md
Rastaban Dec 3, 2019
6e53dc1
Update c6336.md
Rastaban Dec 3, 2019
7516122
Update c6335.md
Rastaban Dec 3, 2019
a7838c3
Update c6334.md
Rastaban Dec 3, 2019
f288dc4
Update c6333.md
Rastaban Dec 3, 2019
02749c1
Update c6332.md
Rastaban Dec 3, 2019
16190d4
Update c6331.md
Rastaban Dec 3, 2019
9dfd276
Update c6329.md
Rastaban Dec 3, 2019
1d4979b
Update c6326.md
Rastaban Dec 3, 2019
54e76ac
Update c6326.md
Rastaban Dec 3, 2019
28f2df9
Update c6324.md
Rastaban Dec 3, 2019
77be1eb
Update c6323.md
Rastaban Dec 3, 2019
fd658d9
Update c6322.md
Rastaban Dec 3, 2019
8d06c77
Update c6320.md
Rastaban Dec 3, 2019
8e94ab6
Update c6319.md
Rastaban Dec 3, 2019
526bd5f
Update c6318.md
Rastaban Dec 3, 2019
fd53f8a
Update c6317.md
Rastaban Dec 3, 2019
a643593
Update c6317.md
Rastaban Dec 3, 2019
252760c
Update c6316.md
Rastaban Dec 3, 2019
7f21781
Update c6315.md
Rastaban Dec 3, 2019
64a9a03
Update c6314.md
Rastaban Dec 3, 2019
b97734f
Update c6313.md
Rastaban Dec 3, 2019
b3f4fb3
Update c6312.md
Rastaban Dec 3, 2019
a0b6d34
Update c6306.md
Rastaban Dec 3, 2019
73ffb9d
Update c6305.md
Rastaban Dec 3, 2019
f97cd0b
Update c6303.md
Rastaban Dec 3, 2019
11f223d
Update c6302.md
Rastaban Dec 3, 2019
1345ce5
Merge branch 'master' into update_examples
Rastaban Dec 3, 2019
4860aef
Update annotating-function-parameters-and-return-values.md
Rastaban Dec 4, 2019
24aac17
Update annotating-structs-and-classes.md
Rastaban Dec 4, 2019
5bf3c1d
Update annotating-locking-behavior.md
Rastaban Dec 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ For the annotations in the following table, when a pointer parameter is being an

A pointer to an array of `s` elements (resp. bytes) that will be written by the function. The array elements do not have to be valid in pre-state, and the number of elements that are valid in post-state is unspecified. If there are annotations on the parameter type, they are applied in post-state. For example, consider the following code.

`typedef _Null_terminated_ wchar_t *PWSTR; void MyStringCopy(_Out_writes_ (size) PWSTR p1, _In_ size_t size, _In_ PWSTR p2);`
```cpp
typedef _Null_terminated_ wchar_t *PWSTR;
void MyStringCopy(_Out_writes_(size) PWSTR p1, _In_ size_t size, _In_ PWSTR p2);
```

In this example, the caller provides a buffer of `size` elements for `p1`. `MyStringCopy` makes some of those elements valid. More importantly, the `_Null_terminated_` annotation on `PWSTR` means that `p1` is null-terminated in post-state. In this way, the number of valid elements is still well-defined, but a specific element count is not required.

Expand Down Expand Up @@ -209,13 +212,14 @@ For the annotations in the following table, when a pointer parameter is being an

`_Out_writes_bytes_all_(s)`

A pointer to an array of `s` elements. The elements do not have to be valid in pre-state. In post-state, the elements up to the `c`-th element must be valid. If the size is known in bytes, scale `s` and `c` by the element size or use the `_bytes_` variant, which is defined as:
A pointer to an array of `s` elements. The elements do not have to be valid in pre-state. In post-state, the elements up to the `c`-th element must be valid. The `_bytes_` variant can be used if the size is known in bytes rather than number of elements.

For example:

`_Out_writes_to_(_Old_(s), _Old_(s)) _Out_writes_bytes_to_(_Old_(s), _Old_(s))`

In other words, every element that exists in the buffer up to `s` in the pre-state is valid in the post-state. For example:

`void *memcpy(_Out_writes_bytes_all_(s) char *p1, _In_reads_bytes_(s) char *p2, _In_ int s); void * wordcpy(_Out_writes_all_(s) DWORD *p1, _In_reads_(s) DWORD *p2, _In_ int s);`
```cpp
void *memcpy(_Out_writes_bytes_all_(s) char *p1, _In_reads_bytes_(s) char *p2, _In_ int s);
void *wordcpy(_Out_writes_all_(s) DWORD *p1, _In_reads_(s) DWORD *p2, _In_ int s);
```

- `_Inout_updates_to_(s,c)`

Expand All @@ -239,19 +243,24 @@ For the annotations in the following table, when a pointer parameter is being an

- `_In_reads_to_ptr_(p)`

A pointer to an array for which the expression `p` - `_Curr_` (that is, `p` minus `_Curr_`) is defined by the appropriate language standard. The elements prior to `p` must be valid in pre-state.
A pointer to an array for which `p - _Curr_` (that is, `p` minus `_Curr_`) is a valid expression. The elements prior to `p` must be valid in pre-state.

For Example:
```cpp
int ReadAllElements(_In_reads_to_ptr_(EndOfArray) const int *Array, const int *EndOfArray);
```

- `_In_reads_to_ptr_z_(p)`

A pointer to a null-terminated array for which the expression `p` - `_Curr_` (that is, `p` minus `_Curr_`) is defined by the appropriate language standard. The elements prior to `p` must be valid in pre-state.
A pointer to a null-terminated array for which expression `p - _Curr_` (that is, `p` minus `_Curr_`) is a valid expression. The elements prior to `p` must be valid in pre-state.

- `_Out_writes_to_ptr_(p)`

A pointer to an array for which the expression `p` - `_Curr_` (that is, `p` minus `_Curr_`) is defined by the appropriate language standard. The elements prior to `p` do not have to be valid in pre-state and must be valid in post-state.
A pointer to an array for which `p - _Curr_` (that is, `p` minus `_Curr_`) is a valid expression. The elements prior to `p` do not have to be valid in pre-state and must be valid in post-state.

- `_Out_writes_to_ptr_z_(p)`

A pointer to a null-terminated array for which the expression `p` - `_Curr_` (that is, `p` minus `_Curr_`) is defined by the appropriate language standard. The elements prior to `p` do not have to be valid in pre-state and must be valid in post-state.
A pointer to a null-terminated array for which `p - _Curr_` (that is, `p` minus `_Curr_`) is a valid expression. The elements prior to `p` do not have to be valid in pre-state and must be valid in post-state.

## Optional Pointer Parameters

Expand Down Expand Up @@ -355,7 +364,7 @@ Output pointer parameters require special notation to disambiguate null-ness on

## Output Reference Parameters

A common use of the reference parameter is for output parameters. For simple output reference parameters—for example, `int&``_Out_` provides the correct semantics. However, when the output value is a pointer—for example `int *&`the equivalent pointer annotations like `_Outptr_ int **` don't provide the correct semantics. To concisely express the semantics of output reference parameters for pointer types, use these composite annotations:
A common use of the reference parameter is for output parameters. For simple output reference parameters such as `int&`, `_Out_` provides the correct semantics. However, when the output value is a pointer such as `int *&`, the equivalent pointer annotations like `_Outptr_ int **` don't provide the correct semantics. To concisely express the semantics of output reference parameters for pointer types, use these composite annotations:

**Annotations and Descriptions**

Expand Down
2 changes: 1 addition & 1 deletion docs/code-quality/annotating-locking-behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The following table lists the locking annotations.
|`_Create_lock_level_(name)`|A statement that declares the symbol `name` to be a lock level so that it may be used in the annotations `_Has_Lock_level_` and `_Lock_level_order_`.|
|`_Has_lock_kind_(kind)`|Annotates any object to refine the type information of a resource object. Sometimes a common type is used for different kinds of resources and the overloaded type is not sufficient to distinguish the semantic requirements among various resources. Here's a list of pre-defined `kind` parameters:<br /><br /> `_Lock_kind_mutex_`<br /> Lock kind ID for mutexes.<br /><br /> `_Lock_kind_event_`<br /> Lock kind ID for events.<br /><br /> `_Lock_kind_semaphore_`<br /> Lock kind ID for semaphores.<br /><br /> `_Lock_kind_spin_lock_`<br /> Lock kind ID for spin locks.<br /><br /> `_Lock_kind_critical_section_`<br /> Lock kind ID for critical sections.|
|`_Has_lock_level_(name)`|Annotates a lock object and gives it the lock level of `name`.|
|`_Lock_level_order_(name1, name2)`|A statement that gives the lock ordering between `name1` and `name2`.|
|`_Lock_level_order_(name1, name2)`|A statement that gives the lock ordering between `name1` and `name2`. Locks that have level `name1` must be acquired before locks that have level `name2`|
|`_Post_same_lock_(expr1, expr2)`|Annotates a function and indicates that in post state the two locks, `expr1` and `expr2`, are treated as if they are the same lock object.|
|`_Releases_exclusive_lock_(expr)`|Annotates a function and indicates that in post state the function decrements by one the exclusive lock count of the lock object that's named by `expr`.|
|`_Releases_lock_(expr)`|Annotates a function and indicates that in post state the function decrements by one the lock count of the lock object that's named by `expr`.|
Expand Down
7 changes: 3 additions & 4 deletions docs/code-quality/annotating-structs-and-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ You can annotate struct and class members by using annotations that act like inv

```cpp
#include <sal.h>
// For FIELD_OFFSET macro
#include <windows.h>

// This _Struct_size_bytes_ is equivalent to what below _Field_size_ means.
_Struct_size_bytes_(FIELD_OFFSET(MyBuffer, buffer) + bufferSize * sizeof(int))
_Struct_size_bytes_(__builtin_offsetof(MyBuffer, buffer) + bufferSize * sizeof(int))
struct MyBuffer
{
static int MaxBufferSize;
Expand All @@ -93,8 +91,9 @@ struct MyBuffer

_Field_range_(1, MaxBufferSize)
int bufferSize;

_Field_size_(bufferSize) // Prefered way - easier to read and maintain.
int buffer[0];
int buffer[]; // Using C99 Flexible array member
};
```

Expand Down
5 changes: 2 additions & 3 deletions docs/code-quality/c26100.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ warning C26100: Race condition. Variable \<var> should be protected by lock \<lo
## Example
The following example generates warning C26100 because there is a violation of the `_Guarded_by_` contract.

```
```cpp
CRITICAL_SECTION gCS;

_Guarded_by_(gCS) int gData;
Expand Down Expand Up @@ -52,8 +52,7 @@ void Unsafe(DATA* p) {
## Example
Occasionally a shared variable only has to be guarded for write access but not for read access. In that case, use the `_Write_guarded_by_` annotation, as shown in the following example.

```

```cpp
CRITICAL_SECTION gCS;

_Guarded_by_(gCS) int gData;
Expand Down
3 changes: 1 addition & 2 deletions docs/code-quality/c26101.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ warning C26101: Failing to use interlocked operation properly for variable \<var
## Example
The following example generates warning C26101 because there is a violation of the `_Interlocked_` contract.

```

```cpp
CRITICAL_SECTION cs;
typedef struct _DATA
{
Expand Down
3 changes: 1 addition & 2 deletions docs/code-quality/c26105.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ warning C26105: Lock order violation. Acquiring lock \<lock> with level \<level>
## Example
The following example generates warning C26105 because there is a lock order inversion in the function `OrderInversion`.

```

```cpp
_Create_lock_level_(MutexLockLevel);
_Create_lock_level_(TunnelLockLevel);
_Create_lock_level_(ChannelLockLevel);
Expand Down
3 changes: 1 addition & 2 deletions docs/code-quality/c26110.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ warning C26110: Caller failing to hold lock \<lock> before calling function \<fu
## Example
In the following example, warning C26110 is generated because the annotation `_Requires_lock_held_` on function `LockRequired` states that the caller of `LockRequired` must acquire the lock before it calls `LockRequired`. Without this annotation, `LockRequired` has to acquire the lock before it accesses any shared data protected by the lock.

```

```cpp
typedef struct _DATA
{
CRITICAL_SECTION cs;
Expand Down
3 changes: 1 addition & 2 deletions docs/code-quality/c26111.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ warning C26111: Caller failing to release lock \<lock> before calling function \
## Example
The following example generates warning C26111 because the `_Requires_lock_not_held_` precondition is violated by the call to `DoNotLock` within the locked section.

```

```cpp
typedef struct _DATA
{
CRITICAL_SECTION cs;
Expand Down
3 changes: 1 addition & 2 deletions docs/code-quality/c26112.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ warning C26112: Caller cannot hold any lock before calling \<func>.
## Example
The following example generates warning C26112 because the `_Requires_no_locks_held_` precondition is violated by the call to `NoLocksAllowed` within the locked section.

```

```cpp
typedef struct _DATA
{
CRITICAL_SECTION cs;
Expand Down
3 changes: 1 addition & 2 deletions docs/code-quality/c26115.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ warning C26115: Failing to release lock \<lock> in function \<func>.
## Example
The following example generates warning C26115 because there is an orphaned lock in a function that is not annotated with `_Acquires_lock_`.

```

```cpp
typedef struct _DATA
{
CRITICAL_SECTION cs;
Expand Down
3 changes: 1 addition & 2 deletions docs/code-quality/c26116.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ warning C26116: Failing to acquire or to hold lock \<lock> in \<func>.
## Example
The following example generates warning C26116 because the function `DoesNotLock` was annotated with `_Acquires_lock_` but does not acquire it. The function `DoesNotHoldLock` generates the warning because it is annotated with `_Requires_lock_held` and does not hold it.

```

```cpp
typedef struct _DATA
{
CRITICAL_SECTION cs;
Expand Down
9 changes: 3 additions & 6 deletions docs/code-quality/c26130.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ warning C26130: Missing annotation \_Requires\_lock\_held\_(\<lock>) or \_No\_co
## Example
In the following example, warning C26130 is generated because a `_Guarded_by_` member is being modified without a lock.

```

```cpp
typedef struct _DATA
{
CRITICAL_SECTION cs;
Expand All @@ -38,8 +37,7 @@ void Init(DATA* p)
## Example
If the previous code is guaranteed to be operated in a single threaded mode, annotate the function by using `_No_competing_thread_`, as shown in the following example.

```

```cpp
typedef struct _DATA
{
CRITICAL_SECTION cs;
Expand All @@ -55,8 +53,7 @@ _No_competing_thread_ void Init(DATA* p)
## Example
Alternatively, you can annotate a code fragment by using `_No_competing_thread_begin_` and `_No_competing_thread_end_`, as follows.

```

```cpp
typedef struct _DATA
{
CRITICAL_SECTION cs;
Expand Down
6 changes: 2 additions & 4 deletions docs/code-quality/c26135.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ warning C26135: Missing annotation \<annotation> at function \<func>.
## Example
The following example generates warning C26135 because an appropriate side effect annotation is missing.

```

```cpp
typedef struct _DATA
{
CRITICAL_SECTION cs;
Expand All @@ -46,8 +45,7 @@ void MyLeave(DATA* p)
## Example
Warning C26135 is also issued when a conditional locking side effect is detected. To annotate a conditional effect, use the `_When_(ConditionExpr, LockAnnotation)` annotation, where `LockAnnotation` is either `_Acquires_lock_` or `_Releases_lock_` and the predicate expression `ConditionExpr` is a Boolean conditional expression. The side effects of other annotations on the same function only occur when `ConditionExpr` evaluates to true. Because `ConditionExpr` is used to relay the condition back to the caller, it must involve variables that are recognized in the calling context. These include function parameters, global or class member variables, or the return value. To see the return value, use a special keyword in the annotation, `return`, as shown in the following example.

```

```cpp
typedef struct _DATA
{
CRITICAL_SECTION cs;
Expand Down
3 changes: 1 addition & 2 deletions docs/code-quality/c26140.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ warning C26140: Undefined lock kind \<lock> in annotation \<annotation> on lock

## Example

```

```cpp
_Has_lock_kind_(MUTEXa) HANDLE gMutex;

struct CorrectExample
Expand Down
4 changes: 2 additions & 2 deletions docs/code-quality/c28103.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ warning C28103: Leaking resource
## Example
The following code example generates this warning:

```
```cpp
res = KeSaveFloatingPointState(buffer);
```

The following code example avoids this warning:

```
```cpp
res = KeSaveFloatingPointState(buffer);
if (NT_SUCCESS(res))
{
Expand Down
2 changes: 1 addition & 1 deletion docs/code-quality/c28104.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ warning C28104: Resource that should have been acquired before function exit was

## Example

```
```cpp
__drv_acquireResourceGlobal(HWLock, lockid)
void GetHardwareLock(lockid)
#pragma warning (suppress: 28104)
Expand Down
4 changes: 2 additions & 2 deletions docs/code-quality/c28105.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Warning C28105: Leaking resource due to an exception
## Example
The following code example generates this warning:

```
```cpp
res = KeSaveFloatingPointState(buffer);

res = AllocateResource(Resource);
Expand All @@ -33,7 +33,7 @@ FreeResource(Resource)

The following code example avoids this warning:

```
```cpp
res = AllocateResource(Resource);
char *p2;

Expand Down
8 changes: 4 additions & 4 deletions docs/code-quality/c28106.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ Warning C28106: Variable already holds resource possibly causing leak
## Example
The following code example generates this warning:

```
```cpp
ExAcquireResourceLite(resource, true);
...
//...
ExAcquireResourceLite(resource, true);
```

The following code example avoids this warning:

```
```cpp
ExAcquireResourceLite(resource1, true);
...
//...
ExAcquireResourceLite(resource2, true);
```
4 changes: 2 additions & 2 deletions docs/code-quality/c28107.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ warning C28107: Resource must be held when calling function
## Example
The following code example generates this warning:

```
```cpp
ExAcquireResourceLite(resource, true);
ExReleaseResourceLite(resource);
```

The following code example avoids this warning:

```
```cpp
KeEnterCriticalRegion();
ExAcquireResourceLite(resource, true);
ExReleaseResourceLite(resource);
Expand Down
8 changes: 4 additions & 4 deletions docs/code-quality/c28108.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ warning C28108: Variable holds an unexpected resource
## Example
The following code example generates this warning:

```
```cpp
KeAcquireInStackSpinLock(spinLock, lockHandle);
...
//...
KeReleaseSpinLock(spinLock, 0);
```

The following code example avoids this warning:

```
```cpp
KeAcquireInStackSpinLock(spinLock, lockHandle);
...
//...
KeReleaseInStackSpinLock(lockHandle);
```
6 changes: 3 additions & 3 deletions docs/code-quality/c28109.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ warning C28109: Variable cannot be held at the time function is called
## Example
The following code example generates this warning:

```
```cpp
ExAcquireResourceLite(resource, true);
...
//...
ExAcquireResourceLite(resource, true);
```

The following code example avoids this warning:

```
```cpp
ExAcquireResourceLite(resource, true);
```
4 changes: 2 additions & 2 deletions docs/code-quality/c28113.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ warning C28113: Accessing a local variable via an Interlocked function
## Example
Typically, the return value of an Interlocked executive support routine is used in subsequent computations, instead of the input arguments. Also, the Interlocked routines only protect the first (leftmost) argument. Using an Interlocked routine in the following way does not protect the value of global and often serves no purpose.

```
```cpp
InterlockedExchange(&local, global)
```

The following form has the same effect on the data and safely accesses the global variable.

```
```cpp
local = InterllockedExchange(&global, global)
```
Loading