Skip to content

Commit aa9d138

Browse files
authored
Merge pull request #4562 from corob-msft/learn/corob/ca-acrolinx-1
Update CA warnings as prototypes
2 parents 1b6776d + 4a14f12 commit aa9d138

File tree

10 files changed

+124
-88
lines changed

10 files changed

+124
-88
lines changed

docs/code-quality/c6001.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
---
2-
description: "Learn more about: C6001"
3-
title: C6001
4-
ms.date: 11/04/2016
2+
description: "Learn more about: Warning C6001"
3+
title: Warning C6001
4+
ms.date: 10/04/2022
55
ms.topic: reference
6-
f1_keywords: ["C6001"]
6+
f1_keywords: ["C6001", "USING_UNINIT_VAR", "__WARNING_USING_UNINIT_VAR"]
77
helpviewer_keywords: ["C6001"]
88
ms.assetid: 55e779f1-7295-48f7-8ce1-b43898b36cd8
99
---
10-
# C6001
10+
# Warning C6001
1111

12-
> warning C6001: using uninitialized memory \<variable>
12+
> Using uninitialized memory '*variable*'.
1313
14-
This warning is reported when an uninitialized local variable is used before it is assigned a value. This could lead to unpredictable results. You should always initialize variables before use.
14+
## Remarks
15+
16+
This warning is reported when an uninitialized local variable is used before it's assigned a value. This usage could lead to unpredictable results. You should always initialize variables before use.
17+
18+
Code analysis name: `USING_UNINIT_VAR`
1519

1620
## Example
1721

docs/code-quality/c6011.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
---
2-
title: C6011
2+
title: Warning C6011
33
description: "Reference for Visual Studio C++ code analysis warning C6011."
4-
ms.date: 03/23/2020
4+
ms.date: 10/04/2022
55
ms.topic: reference
6-
f1_keywords: ["C6011"]
6+
f1_keywords: ["C6011", "DEREF_NULL_PTR", "__WARNING_DEREF_NULL_PTR"]
77
helpviewer_keywords: ["C6011"]
88
ms.assetid: 54b7bc2b-b8f5-43fc-a9a3-8189b03f249a
99
---
10-
# C6011
10+
# Warning C6011
1111

12-
> warning C6011: dereferencing NULL pointer \<name>
12+
> Dereferencing NULL pointer '*pointer-name*'.
13+
14+
## Remarks
1315

1416
This warning indicates that your code dereferences a potentially null pointer. If the pointer value is invalid, the result is undefined. To resolve the issue, validate the pointer before use.
1517

18+
Code analysis name: `DEREF_NULL_PTR`
19+
1620
## Example
1721

1822
The following code generates this warning because a call to `malloc` might return null if insufficient memory is available:
@@ -59,12 +63,12 @@ void f([Pre(Null=Yes)] char* pc)
5963
}
6064
```
6165
62-
The careless use of `malloc` and `free` leads to memory leaks and exceptions. To minimize these kinds of leaks and exception problems altogether, avoid allocating raw memory yourself. Instead, use the mechanisms 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 [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).
66+
The careless use of `malloc` and `free` leads to memory leaks and exceptions. To minimize these kinds of leaks and exception problems altogether, avoid allocating raw memory yourself. Instead, use the mechanisms 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 [`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).
6367
6468
## See also
6569
6670
- [Using SAL Annotations to reduce code defects](using-sal-annotations-to-reduce-c-cpp-code-defects.md)
67-
- [NULL](../c-runtime-library/null-crt.md)
71+
- [`NULL`](../c-runtime-library/null-crt.md)
6872
- [Indirection and Address-of Operators](../c-language/indirection-and-address-of-operators.md)
69-
- [malloc](../c-runtime-library/reference/malloc.md)
70-
- [free](../c-runtime-library/reference/free.md)
73+
- [`malloc`](../c-runtime-library/reference/malloc.md)
74+
- [`free`](../c-runtime-library/reference/free.md)

docs/code-quality/c6014.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ ms.assetid: ef76ec88-74d2-4a3b-b6fe-4b0851ab3372
99
---
1010
# Warning C6014
1111

12-
> warning C6014: Leaking memory.
12+
> Leaking memory '*pointer-name*'.
1313
1414
This warning indicates that the specified pointer points to allocated memory or some other allocated resource that hasn't been freed.
1515

1616
## Remarks
1717

1818
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).
1919

20+
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.
21+
22+
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 warning(disable: 6014)` directive on the line that precedes the opening brace `{` of the function body.
23+
24+
Code analysis name: `MEMORY_LEAK`
25+
2026
## Examples
2127

2228
The following code generates warning C6014:
@@ -76,10 +82,6 @@ int main( )
7682
}
7783
```
7884

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.
80-
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.
82-
8385
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).
8486

8587
```cpp

docs/code-quality/c6029.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
---
2-
description: "Learn more about: C6029"
3-
title: C6029
4-
ms.date: 11/04/2016
2+
description: "Learn more about: Warning C6029"
3+
title: Warning C6029
4+
ms.date: 10/04/2022
55
ms.topic: reference
6-
f1_keywords: ["C6029"]
6+
f1_keywords: ["C6029", "USING_TAINTED_DATA", "__WARNING_USING_TAINTED_DATA"]
77
helpviewer_keywords: ["C6029"]
88
ms.assetid: 07f89261-1b77-4597-9f34-12ce5d569b60
99
---
10-
# C6029
10+
# Warning C6029
1111

12-
> warning C6029: possible buffer overrun in call to \<function>: use of unchecked value
12+
> Possible buffer overrun in call to '*function*': use of unchecked value
1313
14-
This warning indicates that a function that takes a buffer and a size is being passed a unchecked size. The data read-in from some external source has not been verified to see whether it is smaller than the buffer size. An attacker might intentionally specify a much larger than expected value for the size, which will lead to a buffer overrun.
14+
## Remarks
1515

16-
Generally, whenever you read data from an untrusted external source, make sure to verify it for validity. It is usually appropriate to verify the size to make sure it is in the expected range.
16+
This warning indicates that a function that takes a buffer and a size is being passed an unchecked size. The data read-in from some external source hasn't been verified to see whether it's smaller than the buffer size. An attacker might intentionally specify a much larger than expected value for the size, which will lead to a buffer overrun.
17+
18+
Generally, whenever you read data from an untrusted external source, make sure to verify it for validity. It's appropriate to verify the size to make sure it's in the expected range.
19+
20+
Code analysis name: `USING_TAINTED_DATA`
1721

1822
## Example
1923

20-
The following code generates this warning by calling the annotated function [ReadFile](/windows/desktop/api/fileapi/nf-fileapi-readfile) two times. After the first call, the Post attribute property marks the second parameter value untrusted. Therefore, passing an untrusted value in the second call to `ReadFile` generates this warning as shown in the following code:
24+
The following code generates this warning by calling the annotated function [`ReadFile`](/windows/desktop/api/fileapi/nf-fileapi-readfile) two times. After the first call, the Post attribute property marks the second parameter value untrusted. Therefore, passing an untrusted value in the second call to `ReadFile` generates this warning as shown in the following code:
2125

2226
```cpp
2327

docs/code-quality/c6031.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
---
2-
title: C6031
2+
title: Warning C6031
33
description: "Describes C++ Code Analysis warning C6031 and how to resolve it."
4-
ms.date: 03/16/2020
4+
ms.date: 10/04/2022
55
ms.topic: reference
6-
f1_keywords: ["C6031"]
6+
f1_keywords: ["C6031", "RETVAL_IGNORED_FUNC_COULD_FAIL", "__WARNING_RETVAL_IGNORED_FUNC_COULD_FAIL"]
77
helpviewer_keywords: ["C6031"]
88
ms.assetid: 59e1ef0a-b3ca-4ffa-bcb3-ad2bd22ece22
99
---
10-
# C6031
10+
# Warning C6031
1111

12-
> warning C6031: return value ignored: *called-function* could return unexpected value
12+
> Return value ignored: '*called-function*' could return unexpected value
1313
14-
This warning indicates the caller doesn't check a function's return value for failure. Depending on which function is being called, this defect can lead to seemingly random program misbehavior. That includes crashes and data corruptions in error conditions or low-resource situations.
14+
## Remarks
15+
16+
Warning C6031 indicates the caller doesn't check a function's return value for failure. Depending on which function is being called, this defect can lead to seemingly random program misbehavior. That includes crashes and data corruptions in error conditions or low-resource situations.
1517

1618
In general, it isn't safe to assume that calls to functions requiring disk, network, memory, or other resources will succeed. The caller should always check the return value and handle error cases appropriately. Also consider using the `_Must_inspect_result_` annotation, which checks that the value is examined in a useful way.
1719

20+
Code analysis name: `RETVAL_IGNORED_FUNC_COULD_FAIL`
21+
1822
## Example
1923

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

2226
```cpp
2327
#include <stdio.h>
@@ -83,7 +87,7 @@ void test_f()
8387
}
8488
```
8589

86-
In cases where it is necessary to ignore the return value of a function, assign the returned value to `std::ignore`. Assigning to `std::ignore` clearly indicates developer intent and helps in future code maintenance.
90+
In cases where it's necessary to ignore the return value of a function, assign the returned value to `std::ignore`. Assigning to `std::ignore` clearly indicates developer intent and helps in future code maintenance.
8791

8892
```cpp
8993
#include <tuple>

docs/code-quality/c6053.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
---
2-
description: "Learn more about: C6053"
3-
title: C6053
4-
ms.date: 11/04/2016
2+
description: "Learn more about: Warning C6053"
3+
title: Warning C6053
4+
ms.date: 10/04/2022
55
ms.topic: reference
6-
f1_keywords: ["C6053"]
6+
f1_keywords: ["C6053", "MISSING_ZERO_TERMINATION1", "__WARNING_MISSING_ZERO_TERMINATION1"]
77
helpviewer_keywords: ["C6053"]
88
ms.assetid: 8e25566a-e3b9-470a-820d-64221a877c53
99
---
10-
# C6053
10+
# Warning C6053
1111

12-
> warning C6053: call to \<function> may not zero-terminate string \<variable>
12+
> Call to '*function*' may not zero-terminate string '*variable*'.
1313
14-
This warning indicates that the specified function has been called in such a way that the resulting string might not be zero-terminated. This defect might cause an exploitable buffer overrun or crash. This warning is also generated if an annotated function expects a null terminated string is passed a string that is not null terminated.
14+
## Remarks
1515

16-
Most C standard library and Win32 string handling functions require and produce zero-terminated strings. A few 'counted string' functions (including `strncpy`, `wcsncpy`, `_mbsncpy`, `_snprintf`, and `snwprintf`) do not produce zero-terminated strings if they exactly fill their buffer. In this case, a subsequent call to a string function that expects a zero-terminated string will go beyond the end of the buffer looking for the zero. The program should make sure that the string ends with a zero. In general, you should pass a length to the 'counted string' function one smaller than the size of the buffer and then explicitly assign zero to the last character in the buffer.
16+
This warning indicates that the specified function has been called in such a way that the resulting string might not be zero-terminated. This defect might cause an exploitable buffer overrun or crash. This warning is also generated if an annotated function expects a null-terminated string, but you pass a non-null-terminated string.
17+
18+
Most C standard library and Win32 string handling functions require and produce zero-terminated strings. A few 'counted string' functions (including `strncpy`, `wcsncpy`, `_mbsncpy`, `_snprintf`, and `snwprintf`) don't produce zero-terminated strings if they exactly fill their buffer. In this case, a subsequent call to a string function that expects a zero-terminated string will go beyond the end of the buffer looking for the zero. The program should make sure that the string ends with a zero. In general, you should pass a length to the 'counted string' function one smaller than the size of the buffer and then explicitly assign zero to the last character in the buffer.
19+
20+
Code analysis name: `MISSING_ZERO_TERMINATION1`
1721

1822
## Examples
1923

@@ -74,4 +78,4 @@ You should note that this warning is sometimes reported on certain idioms guaran
7478
## See also
7579
7680
- [Using SAL Annotations to reduce code defects](using-sal-annotations-to-reduce-c-cpp-code-defects.md)
77-
- [strncpy_s, _strncpy_s_l, wcsncpy_s, _wcsncpy_s_l, _mbsncpy_s, _mbsncpy_s_l](../c-runtime-library/reference/strncpy-s-strncpy-s-l-wcsncpy-s-wcsncpy-s-l-mbsncpy-s-mbsncpy-s-l.md)
81+
- [`strncpy_s`, `_strncpy_s_l`, `wcsncpy_s`, `_wcsncpy_s_l`, `_mbsncpy_s`, `_mbsncpy_s_l`](../c-runtime-library/reference/strncpy-s-strncpy-s-l-wcsncpy-s-wcsncpy-s-l-mbsncpy-s-mbsncpy-s-l.md)

docs/code-quality/c6054.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
---
2-
title: C6054
2+
title: Warning C6054
33
description: "Reference guide to Microsoft C++ code analysis warning C6054."
4-
ms.date: 04/22/2020
4+
ms.date: 10/04/2022
55
ms.topic: reference
6-
f1_keywords: ["C6054"]
6+
f1_keywords: ["C6054", "MISSING_ZERO_TERMINATION2", "__WARNING_MISSING_ZERO_TERMINATION2"]
77
helpviewer_keywords: ["C6054"]
88
ms.assetid: d573a5c1-7e74-402b-92e6-8085f967aa50
99
---
10-
# C6054
10+
# Warning C6054
1111

12-
> warning C6054: string \<variable> may not be zero-terminated
12+
> String '*variable*' may not be zero-terminated.
1313
1414
## Remarks
1515

1616
This warning indicates that a function that requires a zero-terminated string was passed a non-zero terminated string. A function that expects a zero-terminated string could look for the zero beyond the end of the buffer. This defect might cause an exploitable buffer overrun error or crash. The program should make sure the string passed in ends with a zero.
1717

18+
Code analysis name: `MISSING_ZERO_TERMINATION2`
19+
1820
## Example
1921

2022
The following code generates this warning:
2123

2224
```cpp
23-
// C6054_bad.cpp
25+
// Warning C6054_bad.cpp
2426
// Compile using: cl /W4 /EHsc /c /analyze C6054_bad.cpp
2527
#include <sal.h>
2628

@@ -51,5 +53,5 @@ void g ( )
5153

5254
## See also
5355

54-
- [C6053](../code-quality/c6053.md)
56+
- [Warning C6053](../code-quality/c6053.md)
5557
- [Using SAL Annotations to reduce code defects](using-sal-annotations-to-reduce-c-cpp-code-defects.md)

docs/code-quality/c6059.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
---
2-
description: "Learn more about: C6059"
3-
title: C6059
4-
ms.date: 11/04/2016
2+
description: "Learn more about: Warning C6059"
3+
title: Warning C6059
4+
ms.date: 10/04/2022
55
ms.topic: reference
6-
f1_keywords: ["C6059"]
6+
f1_keywords: ["C6059", "BAD_CONCATENATION", "__WARNING_BAD_CONCATENATION"]
77
helpviewer_keywords: ["C6059"]
88
ms.assetid: 343a4cd1-048a-4edf-bb4b-187097bb6093
99
---
10-
# C6059
10+
# Warning C6059
1111

12-
> warning C6059: Incorrect length parameter in call to \<function>. Pass the number of remaining characters, not the buffer size of \<variable>
12+
> Incorrect length parameter in call to '*function*'. Pass the number of remaining characters, not the buffer size of '*variable*'.
1313
14-
This warning indicates that a call to a string concatenation function is probably passing an incorrect value for the number of characters to concatenate. This defect might cause an exploitable buffer overrun or crash. A common cause of this defect is passing the buffer size, instead of the remaining number of characters in the buffer, to the string manipulation function.
14+
## Remarks
15+
16+
This warning indicates that a call to a string concatenation function is probably passing an incorrect value for the number of characters to concatenate. This defect might cause an exploitable buffer overrun or crash. A common cause of this defect is passing the buffer size (instead of the remaining number of characters in the buffer) to the string manipulation function.
17+
18+
Code analysis name: `BAD_CONCATENATION`
1519

1620
## Example
1721

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

2024
```cpp
2125
#include <string.h>
@@ -27,9 +31,9 @@ void f( )
2731
char *szState ="Washington";
2832
char *szCity="Redmond, ";
2933

30-
strncpy(szTarget,szCity, MAX);
34+
strncpy(szTarget, szCity, MAX);
3135
szTarget[MAX -1] = '\0';
32-
strncat(szTarget, szState, MAX); //wrong size
36+
strncat(szTarget, szState, MAX); // wrong size
3337
// code ...
3438
}
3539
```
@@ -46,14 +50,14 @@ void f( )
4650
char *szState ="Washington";
4751
char *szCity="Redmond, ";
4852
49-
strncpy(szTarget,szCity, MAX);
53+
strncpy(szTarget, szCity, MAX);
5054
szTarget[MAX -1] = '\0';
5155
strncat(szTarget, szState, MAX - strlen(szTarget)); // correct size
5256
// code ...
5357
}
5458
```
5559

56-
To correct this warning using the safe string manipulation function, see the following code:
60+
To correct this warning using the safe string manipulation functions `strncpy_s` and `strncat_s`, see the following code:
5761

5862
```cpp
5963
#include <string.h>
@@ -66,7 +70,7 @@ void f( )
6670
size_t nTargetSize = strlen(szState) + strlen(szCity) + 1;
6771
char *szTarget= new char[nTargetSize];
6872

69-
strncpy_s(szTarget, nTargetSize, szCity,strlen(szCity));
73+
strncpy_s(szTarget, nTargetSize, szCity, strlen(szCity));
7074
strncat_s(szTarget, nTargetSize, szState,
7175
nTargetSize - strlen(szTarget));
7276
// code ...
@@ -76,5 +80,5 @@ void f( )
7680
7781
## See also
7882
79-
- [strncpy_s, _strncpy_s_l, wcsncpy_s, _wcsncpy_s_l, _mbsncpy_s, _mbsncpy_s_l](../c-runtime-library/reference/strncpy-s-strncpy-s-l-wcsncpy-s-wcsncpy-s-l-mbsncpy-s-mbsncpy-s-l.md)
80-
- [strncat_s, _strncat_s_l, wcsncat_s, _wcsncat_s_l, _mbsncat_s, _mbsncat_s_l](../c-runtime-library/reference/strncat-s-strncat-s-l-wcsncat-s-wcsncat-s-l-mbsncat-s-mbsncat-s-l.md)
83+
- [`strncpy_s`, `_strncpy_s_l`, `wcsncpy_s`, `_wcsncpy_s_l`, `_mbsncpy_s`, `_mbsncpy_s_l`](../c-runtime-library/reference/strncpy-s-strncpy-s-l-wcsncpy-s-wcsncpy-s-l-mbsncpy-s-mbsncpy-s-l.md)
84+
- [`strncat_s`, `_strncat_s_l`, `wcsncat_s`, `_wcsncat_s_l`, `_mbsncat_s`, `_mbsncat_s_l`](../c-runtime-library/reference/strncat-s-strncat-s-l-wcsncat-s-wcsncat-s-l-mbsncat-s-mbsncat-s-l.md)

0 commit comments

Comments
 (0)