Skip to content

Commit 17d8649

Browse files
authored
Merge pull request #4559 from MicrosoftDocs/main
10/4 AM Publishing
2 parents edec52c + 7b3240f commit 17d8649

35 files changed

+639
-581
lines changed

docs/code-quality/c28112.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
11
---
22
description: "Learn more about: C28112"
33
title: C28112
4-
ms.date: 11/04/2016
4+
ms.date: 08/25/2022
55
ms.topic: reference
6-
f1_keywords: ["C28112"]
6+
f1_keywords: ["C28112", "INTERLOCKED_ACCESS", "__WARNING_INTERLOCKED_ACCESS"]
77
helpviewer_keywords: ["C28112"]
88
ms.assetid: 2720a5dc-84e9-4f78-a8c7-a320c9f9216b
99
---
10-
# C28112
10+
# Warning C28112
1111

12-
> warning C28112: A variable which is accessed via an Interlocked function must always be accessed via an Interlocked function
12+
> A variable (*parameter-name*) which is accessed via an Interlocked function must always be accessed via an Interlocked function. See line *line-number*: It is not always safe to access a variable which is accessed via the Interlocked\* family of functions in any other way.
1313
14-
See line *[number]*: It is not always safe to access a variable which is accessed via the Interlocked\* family of functions in any other way.
14+
A variable that is accessed by using the Interlocked executive support routines, such as InterlockedCompareExchangeAcquire, is later accessed by using a different function.
1515

16-
A variable that is accessed by using the Interlocked executive support routines, such as InterlockedCompareExchangeAcquire, is later accessed by using a different function. Although certain ordinary assignments, accesses, and comparisons to variables that are used by the Interlocked\* routines can be safely accessed by using a different function, the risk is great enough to justify examining each instance.
16+
## Remarks
17+
18+
`InterlockedXxx` functions are intended to provide atomic operations, but are only atomic with respect to other `InterlockedXxx` functions. Although certain ordinary assignments, accesses, and comparisons to variables that are used by the Interlocked\* routines can be safely accessed by using a different function, the risk is great enough to justify examining each instance.
19+
20+
Code analysis name: INTERLOCKED_ACCESS
1721

1822
## Example
1923

20-
The following code example generates this warning:
24+
The following code generates this warning:
2125

2226
```cpp
23-
inter_var --;
24-
...
27+
inter_var--;
28+
//code
2529
InterlockedIncrement(&inter_var);
2630
```
2731
28-
The following code example avoids this warning:
32+
The following code corrects this warning by strictly accessing `inter_var` through `InterlockedXxx` functions:
2933
3034
```cpp
3135
InterlockedDecrement(&inter_var);
32-
...
36+
//code
3337
InterlockedIncrement(&inter_var);
3438
```
39+
40+
## See Also
41+
42+
[InterlockedIncrement function (wdm.h)](/windows-hardware/drivers/ddi/wdm/nf-wdm-interlockedincrement)
43+
[InterlockedDecrement function (wdm.h)](/windows-hardware/drivers/ddi/wdm/nf-wdm-interlockeddecrement)

docs/code-quality/c28159.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
---
22
description: "Learn more about: C28159"
33
title: C28159
4-
ms.date: 11/04/2016
4+
ms.date: 09/08/2022
55
ms.topic: reference
6-
f1_keywords: ["C28159"]
6+
f1_keywords: ["C28159", "USE_OTHER_FUNCTION", "__WARNING_USE_OTHER_FUNCTION"]
77
helpviewer_keywords: ["C28159"]
88
ms.assetid: fab6cd58-0985-4ef6-89a2-64ed04297437
99
---
10-
# C28159
10+
# Warning C28159
1111

12-
> warning C28159: Consider using another function instead.
12+
> Consider using `*function_name_1*` instead of `*function_name_2*`. Reason: *reason*
1313
14-
This warning is reported for Drivers is suggesting that you use a preferred function call that is semantically equivalent to the function that the driver is calling. This is a general warning message; the annotation `__drv_preferredFunction` was used (possibly with a conditional a `__drv_when`() annotation) to flag a bad coding practice.
14+
This warning occurs when you use a function that is semantically equivalent to an alternative, preferred function call.
15+
16+
## Remarks
17+
18+
C28159 is a general warning message; the annotation `__drv_preferredFunction` was used (possibly with a conditional `__drv_when`() annotation) to flag a bad coding practice.
19+
20+
Code analysis name: USE_OTHER_FUNCTION
1521

1622
## Example
1723

18-
The following code example generates this warning:
24+
The following code example generates this warning. This issue is due to the use of `OemToChar`, which doesn't validate the buffer size:
1925

2026
```cpp
2127
char buff[MAX_PATH];
22-
23-
// if strlen(input) > MAX_PATH
24-
// leads to buffer overrun
25-
OemToChar(buff, input);
28+
OemToChar(buff, input); // If strlen(input) > MAX_PATH, this call leads to buffer overrun
2629
```
2730
28-
The following code example avoids this warning:
31+
The following code example avoids this warning by using the recommended alternative `OemToCharBuff`, which takes in the destination buffer size and limits the copy appropriately:
2932
3033
```cpp
3134
char buff[MAX_PATH];
32-
3335
OemToCharBuff(buff, input, MAX_PATH);
3436
```

docs/code-quality/c28160.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
---
22
description: "Learn more about: C28160"
33
title: C28160
4-
ms.date: 11/04/2016
4+
ms.date: 09/08/2022
55
ms.topic: reference
6-
f1_keywords: ["C28160"]
6+
f1_keywords: ["C28160", "ERROR", "__WARNING_ERROR"]
77
helpviewer_keywords: ["C28160"]
88
ms.assetid: cab15f6b-909c-4cc8-81a0-c24ac7c91c7c
99
---
10-
# C28160
10+
# Warning C28160
1111

12-
> warning C28160: Error annotation
12+
> Error annotation: *reason*
1313
14-
This warning is reported when a `__drv_error` annotation has been encountered. This annotation is used to flag coding practices that should be fixed, and can be used with a `__drv_when` annotation to indicate specific combinations of parameters.
14+
This warning is reported when a `__drv_error` annotation has been encountered.
15+
16+
## Remarks
17+
18+
This annotation is used to flag coding practices that should be fixed, and can be used with a `__drv_when` annotation to indicate specific combinations of parameters.
19+
20+
Code analysis name: ERROR

docs/code-quality/c28208.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,41 @@
11
---
22
description: "Learn more about: C28208"
33
title: C28208
4-
ms.date: 11/04/2016
4+
ms.date: 10/03/2022
55
ms.topic: reference
6-
f1_keywords: ["C28208"]
6+
f1_keywords: ["C28208", "FUNCTION_TYPE_REDECLARATION", "__WARNING_FUNCTION_TYPE_REDECLARATION"]
77
helpviewer_keywords: ["C28208"]
88
ms.assetid: e9a8ce37-3b05-4202-b078-5570ae496d1d
99
---
10-
# C28208
10+
# Warning C28208
1111

12-
> warning C28208: Function \<function> was previously defined with a different parameter list at \<file>(\<line>). Some analysis tools will yield incorrect results
12+
> Function *function_name* was previously defined with a different parameter list at *file_name*(*line_number*). Some analysis tools will yield incorrect results
1313
14-
This warning is reported when a function's known definition doesn't match another occurrence.
14+
## Remarks
15+
16+
This warning almost always accompanies [Compiler Warning (level 1) C4028](../error-messages/compiler-warnings/compiler-warning-level-1-c4028.md). Both warn of a mismatch between the parameters of a function's declaration and its definition. However, this specific error indicates a more niche case than C4028. C28208 indicates not only that a mismatch exists, but that it also can cause issues with analysis tools. This warning most notably occurs when the mismatch exists between a `typedef` function pointer and the definition of that function. This warning is demonstrated in the example below.
17+
18+
Code analysis name: `FUNCTION_TYPE_REDECLARATION`
19+
20+
## Example
21+
22+
The following code generates C28208. `test_type` declares `my_test1` and `my_test2` to take a `void*` parameter, but the definition of `my_test1` takes an `int*` parameter instead. `my_test2` avoids this issue because the definition parameters match the declaration parameters.
23+
24+
```cpp
25+
// c28208_example.h
26+
typedef void test_type(void*);
27+
```
28+
29+
```cpp
30+
// c28208_example.cpp
31+
#include "c28208_example.h"
32+
test_type my_test1;
33+
test_type my_test2;
34+
void my_test1(int* x){}; // Generates C28208
35+
void my_test2(void* x){}; // Doesn't generate C28208
36+
37+
int main()
38+
{
39+
// Code
40+
}
41+
```

docs/code-quality/c28213.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,56 @@
11
---
22
description: "Learn more about: C28213"
33
title: C28213
4-
ms.date: 11/04/2016
4+
ms.date: 09/08/2022
55
ms.topic: reference
6-
f1_keywords: ["C28213"]
6+
f1_keywords: ["C28213", "BAD_USEHEADER", "__WARNING_BAD_USEHEADER"]
77
helpviewer_keywords: ["C28213"]
88
ms.assetid: e141a12a-4c46-47eb-aa9d-a6444472cfaa
99
---
10-
# C28213
10+
# Warning C28213
1111

12-
> warning C28213: The `_Use_decl_annotations_` annotation must be used to reference, without modification, a prior declaration.
12+
> The `_Use_decl_annotations_` annotation must be used to reference, without modification, a prior declaration.
1313
14-
`_Use_decl_annotations_` tells the compiler to use the annotations from an earlier declaration of the function. If no earlier declaration can be found, or if the current declaration makes changes to the annotations than this warning is emitted.
14+
## Remarks
15+
16+
`_Use_decl_annotations_` tells the compiler to use the annotations from an earlier declaration of the function. If no earlier declaration can be found, or if the current declaration makes changes to the annotations, then this warning is emitted.
17+
18+
Code analysis name: BAD_USEHEADER
1519

1620
## Example
1721

22+
The following code generates C28160. The `buffer` parameter annotation doesn't match between the two files.
23+
24+
*From example.h:*
25+
1826
```cpp
19-
// from example.h
2027
void example_func(_Out_writes_(n) char* buffer, int n);
28+
```
29+
30+
*From example.cpp:*
2131
22-
// from example.cpp
32+
```cpp
2333
_Use_decl_annotations_
2434
void example_func(_Out_writes_z_(n) char* buffer, int n)
2535
{
26-
// ...
27-
buffer[n] = '\0';
36+
buffer[n] = '\0';
2837
}
2938
```
3039

31-
The `buffer` parameter annotation does not match between the two files. This can be fixed by either changing the annotation so they match at all locations, or by removing all annotations except `_Use_decl_annotations_` from the function definition. In this example `_Out_writes_z_` appears to be correct so we will move that to the function declaration in the header file.
40+
This issue can be fixed by either changing the annotation so they match at all locations, or by removing all annotations except `_Use_decl_annotations_` from the function definition. In this example, `_Out_writes_z_` appears to be correct so we'll move that to the function declaration in the header file. The following code resolves this warning:
3241

33-
```cpp
42+
*From example.h:*
3443

35-
// from example.h
44+
```cpp
3645
void example_func(_Out_writes_z_(n) char* buffer, int n);
46+
```
3747
38-
// from example.cpp
48+
*From example.cpp:*
49+
50+
```cpp
3951
_Use_decl_annotations_
40-
void example_func(char* buffer, int n)
52+
void example_func(_Out_writes_z_(n) char* buffer, int n)
4153
{
42-
// ...
43-
buffer[n] = '\0';
54+
buffer[n] = '\0';
4455
}
4556
```

docs/code-quality/c28285.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
---
22
description: "Learn more about: C28285"
33
title: C28285
4-
ms.date: 12/17/2019
4+
ms.date: 09/22/2022
55
ms.topic: reference
6-
f1_keywords: ["C28285"]
6+
f1_keywords: ["C28285", "SPEC_INVALID_SYNTAX2", "__WARNING_SPEC_INVALID_SYNTAX2"]
77
helpviewer_keywords: ["C28285"]
88
ms.assetid: 6197eb0f-7e1e-4c3e-b097-1f6481405994
99
---
10-
# C28285
10+
# Warning C28285
1111

12-
> warning C28285: For function 'function_name', syntax error in 'annotation'
12+
> For function '*function-name*', syntax error in '*annotation*'
1313
14-
The Code Analysis tool reports this warning for syntax errors in the SAL annotation. The SAL parser will recover by discarding the malformed annotation.
14+
## Remarks
15+
16+
The Code Analysis tool reports this warning for syntax errors in the SAL annotation. The SAL parser will recover by discarding the malformed annotation. Double check the documentation for the SAL annotations being used and try to simplify the annotation. You shouldn't use implementation layer annotations such as `__declspec("SAL_begin")` directly. If you're using that layer, then change them into higher layers such as `_In_`/`_Out_`/`_Ret_`. For more information, see [Annotating Function Parameters and Return Values](annotating-function-parameters-and-return-values.md).
1517

1618
## Example
1719

20+
The following code generates this warning. The argument `(2,n)` is malformed and will cause a C28285 warning after the `_Out_writes_z_` macro is expanded.
21+
1822
```cpp
19-
// The argument '(n,2)' is malformed and will cause a C28285 warning after the _Out_writes_z_ macro is expanded.
2023
void example_func(_Out_writes_z_((2,n)) char* buffer, int n)
2124
{
22-
// ...
23-
buffer[n] = '\0';
25+
buffer[n] = '\0';
2426
}
2527
```
2628
27-
Double check the documentation to the SAL annotations being used and try to simplify the annotation. You should not use implementation layer annotations such as `__declspec("SAL_begin")` directly. If you are using that layer then change them into higher layers such as `_In_`/`_Out_`/`_Ret_`. See [Annotating Function Parameters and Return Values](annotating-function-parameters-and-return-values.md) for more information.
29+
The following code remediates this warning by correcting the malformed annotation
2830
2931
```cpp
3032
void example_func(_Out_writes_z_(n) char* buffer, int n)
3133
{
32-
// ...
33-
buffer[n] = '\0';
34+
buffer[n] = '\0';
3435
}
3536
```
37+

docs/code-quality/c33010.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@ description: C33010 warning for enums
44
keywords: c33010
55
author: hwisungi
66
ms.author: hwisungi
7-
ms.date: 06/20/2020
7+
ms.date: 09/08/2022
88
ms.topic: reference
9-
f1_keywords: ["C33010"]
9+
f1_keywords: ["C33010", "UNCHECKED_LOWER_BOUND_FOR_ENUMINDEX", "__WARNING_UNCHECKED_LOWER_BOUND_FOR_ENUMINDEX"]
1010
helpviewer_keywords: ["C33010"]
1111
dev_langs: ["C++"]
1212
---
13-
# C33010
13+
# Warning C33010
1414

15-
> Warning C33010: Unchecked lower bound for enum 'enum' used as index.
15+
> Unchecked lower bound for enum *enum_name* used as index.
1616
17-
This warning is triggered for an enum that is used as an index into an array,
18-
if the upper bound is checked for its value, but not the lower bound.
17+
This warning is triggered if an enum is both used as an index into an array and isn't checked on the lower bound.
18+
19+
## Remarks
20+
21+
Code using enumerated types as indexes for arrays will often check for the upper bound in order to ensure the index isn't out of range. Because an enum variable is signed by default, it can have a negative value. A negative array index can allow arbitrary memory to be read, used, or even executed.
22+
23+
Code analysis name: UNCHECKED_LOWER_BOUND_FOR_ENUMINDEX
1924

2025
## Example
2126

22-
Code using enumerated types as indexes for arrays will often check for the upper bound
23-
in order to ensure the index is not out of range. Because an enum variable is signed by default,
24-
it can have a negative value. If it is used as an index into an array of values or an array of function pointers,
25-
a negative value can allow arbitrary memory to be read, used, or even executed.
27+
The following code generates this warning. `idx` is used as an index to access `functions`, but the lower bound is never checked.
2628

2729
```cpp
2830
typedef void (*PFN)();
@@ -41,14 +43,13 @@ void foo(Index idx, PFN(&functions)[5])
4143
if (idx > Index::Max)
4244
return;
4345

44-
auto pfn = functions[static_cast<int>(idx)]; // C33010
46+
auto pfn = functions[static_cast<int>(idx)];
4547
if (pfn != nullptr)
4648
(*pfn)();
47-
// ......
4849
}
4950
```
5051
51-
These warnings are corrected by checking the index value for lower bound as well:
52+
The following code remediates this warning by checking the lower bound as well to ensure `idx` isn't negative:
5253
5354
```cpp
5455
typedef void (*PFN)();
@@ -67,10 +68,9 @@ void foo(Index idx, PFN(&functions)[5])
6768
if (idx < Index::Zero || idx > Index::Max)
6869
return;
6970
70-
auto pfn = functions[static_cast<int>(idx)]; // OK
71+
auto pfn = functions[static_cast<int>(idx)];
7172
if (pfn != nullptr)
7273
(*pfn)();
73-
// ......
7474
}
7575
```
7676

0 commit comments

Comments
 (0)