Skip to content

Commit cc49ee5

Browse files
committed
Consistency pass on some CQ warnings
1 parent 5906e8c commit cc49ee5

21 files changed

+274
-211
lines changed

docs/code-quality/c28208.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Learn more about: C28208"
33
title: C28208
4-
ms.date: 08/30/2022
4+
ms.date: 10/03/2022
55
ms.topic: reference
66
f1_keywords: ["C28208", "FUNCTION_TYPE_REDECLARATION", "__WARNING_FUNCTION_TYPE_REDECLARATION"]
77
helpviewer_keywords: ["C28208"]
@@ -13,27 +13,26 @@ ms.assetid: e9a8ce37-3b05-4202-b078-5570ae496d1d
1313
1414
## Remarks
1515

16-
This warning will almost always accompany [Compiler Warning (level 1) C4028](/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4028). 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.
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.
1717

18-
Code analysis name: FUNCTION_TYPE_REDECLARATION
18+
Code analysis name: `FUNCTION_TYPE_REDECLARATION`
1919

2020
## Example
2121

22-
The following code will generate C28208. `test_type` takes in a void pointer in its declaration, but `my_test1` takes in an integer pointer instead. `my_test2` remediates this issue by making sure the definition parameter match the declaration parameters.
23-
24-
*From example.h:*
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.
2523

2624
```cpp
25+
// c28208_example.h
2726
typedef void test_type(void*);
2827
```
2928
30-
*From example.cpp:*
31-
3229
```cpp
30+
// c28208_example.cpp
31+
#include "c28208_example.h"
3332
test_type my_test1;
3433
test_type my_test2;
35-
void my_test1(int* x){}; // Will generate C28208
36-
void my_test2(void* x){}; // Will not generate C28208
34+
void my_test1(int* x){}; // Generates C28208
35+
void my_test2(void* x){}; // Doesn't generate C28208
3736
3837
int main()
3938
{

docs/code-quality/c6014.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
---
2-
description: "Learn more about: C6014"
3-
title: C6014
4-
ms.date: 11/04/2016
2+
description: "Learn more about: Warning C6014"
3+
title: Warning C6014
4+
ms.date: 10/03/2022
55
ms.topic: reference
6-
f1_keywords: ["C6014"]
6+
f1_keywords: ["C6014", "MEMORY_LEAK", "__WARNING_MEMORY_LEAK"]
77
helpviewer_keywords: ["C6014"]
88
ms.assetid: ef76ec88-74d2-4a3b-b6fe-4b0851ab3372
99
---
10-
# C6014
10+
# Warning C6014
1111

1212
> warning C6014: Leaking memory.
1313
14-
This warning indicates that the specified pointer points to allocated memory or some other allocated resource that has not been freed. The analyzer checks for this condition only when the `_Analysis_mode_(_Analysis_local_leak_checks_)` SAL annotation is specified. By default, this annotation is specified for Windows kernel mode (driver) code. For more information about SAL annotations, see [Using SAL Annotations to Reduce C/C++ Code Defects](../code-quality/using-sal-annotations-to-reduce-c-cpp-code-defects.md).
14+
This warning indicates that the specified pointer points to allocated memory or some other allocated resource that hasn't been freed.
15+
16+
## Remarks
17+
18+
The analyzer checks for this condition only when the `_Analysis_mode_(_Analysis_local_leak_checks_)` SAL annotation is specified. By default, this annotation is specified for Windows kernel mode (driver) code. For more information about SAL annotations, see [Using SAL Annotations to Reduce C/C++ Code Defects](../code-quality/using-sal-annotations-to-reduce-c-cpp-code-defects.md).
1519

1620
## Examples
1721

18-
The following code generates this warning:
22+
The following code generates warning C6014:
1923

2024
```cpp
2125
// cl.exe /analyze /EHsc /nologo /W4
@@ -72,11 +76,11 @@ int main( )
7276
}
7377
```
7478

75-
This warning is reported for both memory and resource leaks when the resource is commonly *aliased* to another location. Memory is aliased when a pointer to the memory escapes the function by means of an `_Out_` parameter annotation, global variable, or return value. This warning can be reported on function exit if the argument is annotated as having been expected to be released.
79+
This warning is reported for both memory and resource leaks when the resource is commonly *aliased* to another location. Memory is aliased when a pointer to the memory escapes the function by using an `_Out_` parameter annotation, global variable, or return value. This warning can be reported on function exit if the argument is annotated that its release is expected.
7680

77-
Note that Code Analysis will not recognize the actual implementation of a memory allocator (involving address arithmetic) and will not recognize that memory is allocated (although many wrappers will be recognized). In this case, the analyzer does not recognize that the memory was allocated and issues this warning. To suppress the false positive, use a `#pragma` directive on the line that precedes the opening brace `{` of the function body.
81+
Code Analysis won't recognize the actual implementation of a memory allocator (involving address arithmetic) and won't recognize that memory is allocated (although many wrappers will be recognized). In this case, the analyzer doesn't recognize that the memory was allocated and issues this warning. To suppress the false positive, use a `#pragma` directive on the line that precedes the opening brace `{` of the function body.
7882

79-
To avoid these kinds of potential leaks altogether, use the mechanisms that are provided by the C++ Standard Template Library (STL). These include [shared_ptr](../standard-library/shared-ptr-class.md), [unique_ptr](../standard-library/unique-ptr-class.md), and [vector](../standard-library/vector.md). For more information, see [Smart Pointers](../cpp/smart-pointers-modern-cpp.md) and [C++ Standard Library](../standard-library/cpp-standard-library-reference.md).
83+
To avoid these kinds of potential leaks altogether, use the mechanisms that are provided by the C++ Standard Library (STL). These include [`shared_ptr`](../standard-library/shared-ptr-class.md), [`unique_ptr`](../standard-library/unique-ptr-class.md), and containers such as [`vector`](../standard-library/vector.md). For more information, see [Smart pointers](../cpp/smart-pointers-modern-cpp.md) and [C++ Standard Library](../standard-library/cpp-standard-library-reference.md).
8084

8185
```cpp
8286
// cl.exe /analyze /EHsc /nologo /W4
@@ -110,4 +114,4 @@ int main( )
110114
111115
## See also
112116
113-
[C6211](../code-quality/c6211.md)
117+
[Warning C6211](../code-quality/c6211.md)

docs/code-quality/c6064.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
description: "Learn more about: C6064"
3-
title: C6064
4-
ms.date: 09/14/2022
2+
description: "Learn more about: Warning C6064"
3+
title: Warning C6064
4+
ms.date: 10/03/2022
55
ms.topic: reference
66
f1_keywords: ["C6064", "MISSING_INTEGER_ARGUMENT_TO_FORMAT_FUNCTION", "__WARNING_MISSING_INTEGER_ARGUMENT_TO_FORMAT_FUNCTION"]
77
helpviewer_keywords: ["C6064"]
@@ -11,24 +11,28 @@ ms.assetid: d8f126aa-b093-440e-820f-65b8e6cffaba
1111

1212
> Missing integer argument to '*function-name*' corresponding to conversion specifier '*number*'
1313
14-
This warning indicates that not enough arguments are being provided to match a format string and one of the missing arguments is an integer.
14+
This warning indicates that not enough arguments are provided to match a format string and one of the missing arguments is an integer.
1515

1616
## Remarks
1717

1818
This defect is likely to cause incorrect output and, in more dangerous cases, can lead to stack overflow.
1919

20-
Code analysis name: MISSING_INTEGER_ARGUMENT_TO_FORMAT_FUNCTION
20+
Code analysis name: `MISSING_INTEGER_ARGUMENT_TO_FORMAT_FUNCTION`
2121

2222
## Example
2323

24-
The following code generates this warning because an incorrect number of arguments were used in the call to `sprintf_s` and the missing argument was an integer. Had the unsafe function `sprintf` been used instead of the safer variant `sprintf_s`, this code would likely cause a stack overflow instead of just an unexpected output:
24+
The following code generates this warning because an incorrect number of arguments were used in the call to `sprintf_s` and the missing argument was an integer. If the unsafe function `sprintf` was used instead of the safer variant `sprintf_s`, this code would likely cause a stack overflow instead of just an unexpected output:
2525

2626
```cpp
2727
void f()
2828
{
2929
char buff[8];
3030
char *string="Hello";
31-
sprintf_s(buff, sizeof(buff), "%s %d", string); // Attempts to print "Hello 256" or approximate, which cannot fit in the 8 char buffer. This would overflow if sprintf had been used instead
31+
sprintf_s(buff, sizeof(buff), "%s %d", string); // Attempts to print "Hello "
32+
// followed by a number up to eleven characters long, depending on the garbage
33+
// found on the stack. Any number other than a single non-negative digit can't
34+
// fit in the 8 char buffer and leave room for the trailing null. If sprintf
35+
// had been used instead, it would overflow.
3236
}
3337
```
3438

@@ -45,4 +49,4 @@ void f()
4549

4650
## See also
4751

48-
[sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l](/cpp/c-runtime-library/reference/sprintf-s-sprintf-s-l-swprintf-s-swprintf-s-l)
52+
[`sprintf_s`, `_sprintf_s_l`, `swprintf_s`, `_swprintf_s_l`](../c-runtime-library/reference/sprintf-s-sprintf-s-l-swprintf-s-swprintf-s-l.md)

docs/code-quality/c6211.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
---
22
description: "Learn more about: C6211"
33
title: C6211
4-
ms.date: 11/04/2016
4+
ms.date: 10/03/2022
55
ms.topic: reference
6-
f1_keywords: ["C6211"]
6+
f1_keywords: ["C6211", "MEMORY_LEAK_EXCEPTION", "__WARNING_MEMORY_LEAK_EXCEPTION"]
77
helpviewer_keywords: ["C6211"]
88
ms.assetid: 9b68243b-534c-4a05-b789-bb155dfcba1e
99
---
1010
# C6211
1111

12-
> warning C6211: Leaking memory \<pointer> due to an exception. Consider using a local catch block to clean up memory
12+
> warning C6211: Leaking memory '*pointer*' due to an exception. Consider using a local catch block to clean up memory
1313
14-
This warning indicates that allocated memory is not being freed when an exception is thrown. The statement at the end of the path could throw an exception. The analyzer checks for this condition only when the `_Analysis_mode_(_Analysis_local_leak_checks_)` SAL annotation is specified. By default, this annotation is specified for Windows kernel mode (driver) code. For more information about SAL annotations, see [Using SAL Annotations to Reduce C/C++ Code Defects](../code-quality/using-sal-annotations-to-reduce-c-cpp-code-defects.md).
14+
This warning indicates that allocated memory isn't freed when an exception is thrown. The statement at the end of the path could throw an exception.
15+
16+
## Remarks
17+
18+
The analyzer checks for this condition only when the `_Analysis_mode_(_Analysis_local_leak_checks_)` SAL annotation is specified. By default, this annotation is specified for Windows kernel mode (driver) code. For more information about SAL annotations, see [Using SAL Annotations to Reduce C/C++ Code Defects](../code-quality/using-sal-annotations-to-reduce-c-cpp-code-defects.md).
19+
20+
Code analysis name: `MEMORY_LEAK_EXCEPTION`
1521

1622
## Example
1723

18-
The following code generates this warning because an exception could be thrown during the second allocation and thereby leak the first allocation, or an exception could be thrown somewhere in the code that's represented by the "`code ...`" comment and thereby leak both allocations.
24+
The following code generates warning C6211 because an exception could be thrown during the second allocation and thereby leak the first allocation. Or, an exception could be thrown somewhere in the code that's represented by the "`code ...`" comment and thereby leak both allocations.
1925

2026
```cpp
2127
// cl.exe /analyze /c /EHsc /nologo /W4
@@ -70,7 +76,7 @@ void f()
7076
}
7177
```
7278

73-
To avoid these kinds of potential leaks altogether, use the mechanisms that are provided by the C++ Standard Template Library (STL). These include [shared_ptr](../standard-library/shared-ptr-class.md), [unique_ptr](../standard-library/unique-ptr-class.md), and [vector](../standard-library/vector.md). For more information, see [Smart Pointers](../cpp/smart-pointers-modern-cpp.md) and [C++ Standard Library](../standard-library/cpp-standard-library-reference.md).
79+
To avoid these kinds of potential leaks altogether, use the mechanisms that are provided by the C++ Standard Library (STL). These include [`shared_ptr`](../standard-library/shared-ptr-class.md), [`unique_ptr`](../standard-library/unique-ptr-class.md), and containers such as [`vector`](../standard-library/vector.md). For more information, see [Smart pointers](../cpp/smart-pointers-modern-cpp.md) and [C++ Standard Library](../standard-library/cpp-standard-library-reference.md).
7480

7581
```cpp
7682
// cl.exe /analyze /c /EHsc /nologo /W4
@@ -107,4 +113,4 @@ void f( )
107113
108114
## See also
109115
110-
[C++ Exception Handling](../cpp/exception-handling-in-visual-cpp.md)
116+
[C++ exception handling](../cpp/exception-handling-in-visual-cpp.md)

docs/code-quality/c6214.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
---
2-
description: "Learn more about: C6214"
3-
title: C6214
4-
ms.date: 11/04/2016
2+
description: "Learn more about: Warning C6214"
3+
title: Warning C6214
4+
ms.date: 10/03/2022
55
ms.topic: reference
6-
f1_keywords: ["C6214"]
6+
f1_keywords: ["C6214", "CAST_HRESULT_TO_BOOL", "__WARNING_CAST_HRESULT_TO_BOOL"]
77
helpviewer_keywords: ["C6214"]
88
ms.assetid: 233e2395-61c1-4a3b-a54b-f19a9ffc31a8
99
---
10-
# C6214
10+
# Warning C6214
1111

12-
> warning C6214: cast between semantically different integer types: HRESULT to a Boolean type
12+
> Cast between semantically different integer types: HRESULT to a Boolean type
1313
14-
This warning indicates that an `HRESULT` is being cast to a Boolean type. The success value (`S_OK`) of an `HRESULT` equals 0. However, 0 indicates failure for a Boolean type. Casting an `HRESULT` to a Boolean type and then using it in a test expression will yield an incorrect result. Sometimes, this warning occurs if an `HRESULT` is being stored in a Boolean variable. Any comparison that uses the Boolean variable to test for `HRESULT` success or failure could lead to incorrect results.
14+
This warning indicates that an `HRESULT` is being cast to a Boolean type. The success value (`S_OK`) of an `HRESULT` equals 0. However, 0 indicates failure for a Boolean type. Casting an `HRESULT` to a Boolean type and then using it in a test expression will yield an incorrect result.
15+
16+
## Remarks
17+
18+
Sometimes, this warning occurs if an `HRESULT` is being stored in a Boolean variable. Any comparison that uses the Boolean variable to test for `HRESULT` success or failure could lead to incorrect results.
19+
20+
Code analysis name: `CAST_HRESULT_TO_BOOL`
1521

1622
## Example
1723

18-
The following code generates this warning:
24+
The following code generates warning C6214:
1925

2026
```cpp
2127
#include <windows.h>
@@ -66,10 +72,10 @@ For this warning, the `SCODE` type is equivalent to `HRESULT`.
6672

6773
Usually, the `SUCCEEDED` or `FAILED` macro should be used to test the value of an `HRESULT`.
6874

69-
For more information, see one of the following topics:
75+
For more information, see one of the following articles:
7076

71-
[SUCCEEDED](/windows/desktop/api/winerror/nf-winerror-succeeded)
77+
[`SUCCEEDED`](/windows/desktop/api/winerror/nf-winerror-succeeded)
7278

73-
[FAILED](/windows/desktop/api/winerror/nf-winerror-failed)
79+
[`FAILED`](/windows/desktop/api/winerror/nf-winerror-failed)
7480

75-
To leverage modern C++ memory allocation methodology, use the mechanisms that are provided by the C++ Standard Template Library (STL). These include [shared_ptr](../standard-library/shared-ptr-class.md), [unique_ptr](../standard-library/unique-ptr-class.md), and [vector](../standard-library/vector.md). For more information, see [Smart Pointers](../cpp/smart-pointers-modern-cpp.md) and [C++ Standard Library](../standard-library/cpp-standard-library-reference.md).
81+
To make use of modern C++ memory allocation methodology, use the mechanisms that are provided by the C++ Standard Library (STL). These include [`shared_ptr`](../standard-library/shared-ptr-class.md), [`unique_ptr`](../standard-library/unique-ptr-class.md), and containers such as [`vector`](../standard-library/vector.md). For more information, see [Smart pointers](../cpp/smart-pointers-modern-cpp.md) and [C++ Standard Library](../standard-library/cpp-standard-library-reference.md).

0 commit comments

Comments
 (0)