Skip to content

Commit 5fee611

Browse files
authored
Merge pull request #4255 from MicrosoftDocs/main
5/2 AM Publishing
2 parents b2ae94b + 5157082 commit 5fee611

12 files changed

+112
-27
lines changed

docs/atl-mfc-shared/allocating-and-releasing-memory-for-a-bstr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ In general, the rules for allocating and releasing memory allocated for `BSTR`s
2424

2525
[!code-cpp[NVC_ATLMFC_Utilities#195](../atl-mfc-shared/codesnippet/cpp/allocating-and-releasing-memory-for-a-bstr_4.cpp)]
2626

27-
- When you implement a function that returns a `BSTR`, allocate the string but do not free it. The receiving the function releases the memory. For example:
27+
- When you implement a function that returns a `BSTR`, allocate the string but do not free it. The receiving function releases the memory. For example:
2828

2929
[!code-cpp[NVC_ATLMFC_Utilities#196](../atl-mfc-shared/codesnippet/cpp/allocating-and-releasing-memory-for-a-bstr_5.cpp)]
3030

docs/code-quality/c26455.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
---
2-
description: "Learn more about: C26455 DEFAULT_CTOR_NOEXCEPT"
3-
title: C26455
4-
ms.date: 12/14/2018
5-
ms.topic: "conceptual"
2+
description: "Learn more about the C26455 DEFAULT_CTOR_NOEXCEPT C++ Core Guidelines Checker warning. Default constructors shouldn't do anything that can throw."
3+
title: C26455 DEFAULT_CTOR_NOEXCEPT
4+
ms.date: 04/29/2022
5+
ms.topic: reference
66
f1_keywords: ["C26455"]
77
helpviewer_keywords: ["C26455"]
88
ms.assetid: 27e86063-d969-49d8-8912-dcc2dc57249f
99
author: kylereedmsft
1010
ms.author: kylereed
11+
ms.custom: kr2b-contr-experiment
1112
---
1213
# C26455 DEFAULT_CTOR_NOEXCEPT
1314

docs/code-quality/c26456.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
---
2-
description: "Learn more about: C26456 DONT_HIDE_OPERATORS"
3-
title: C26456
4-
ms.date: 12/14/2018
5-
ms.topic: "conceptual"
2+
description: "Learn more about the C26456 DONT_HIDE_OPERATORS C++ Core Guidelines Checker warning. Hiding base methods is error prone and makes code harder to read."
3+
title: C26456 DONT_HIDE_OPERATORS
4+
ms.date: 04/29/2022
5+
ms.topic: reference
66
f1_keywords: ["C26456"]
77
helpviewer_keywords: ["C26456"]
88
ms.assetid: 3a3ad636-0938-40b5-93ce-169322e2ff23
99
author: kylereedmsft
1010
ms.author: kylereed
11+
ms.custom: kr2b-contr-experiment
1112
---
1213
# C26456 DONT_HIDE_OPERATORS
1314

docs/code-quality/c26476.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
---
2-
description: "Learn more about: C26476 USE_VARIANT"
3-
title: C26476
4-
ms.date: 12/14/2018
5-
ms.topic: "conceptual"
2+
description: "Learn more about the C26476 USE_VARIANT C++ Core Guidelines Checker warning. Use a type-safe alternative to union, which is preferred in modern code."
3+
title: C26476 USE_VARIANT
4+
ms.date: 04/29/2022
5+
ms.topic: reference
66
f1_keywords: ["C26476"]
77
helpviewer_keywords: ["C26476"]
88
ms.assetid: bb2b3b26-9a84-4d81-8bae-ad9a5577c8a6
99
author: kylereedmsft
1010
ms.author: kylereed
11+
ms.custom: kr2b-contr-experiment
1112
---
13+
1214
# C26476 USE_VARIANT
1315

1416
`std::variant` provides a type-safe alternative to `union` and should be preferred in modern code.

docs/code-quality/c26477.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
---
2-
description: "Learn more about: C26477 USE_NULLPTR_NOT_CONSTANT"
3-
title: C26477
4-
ms.date: 12/14/2018
5-
ms.topic: "conceptual"
2+
description: "Learn more about the C26477 USE_NULLPTR_NOT_CONSTANT C++ Core Guidelines Checker warning. The nullptr value allows overloads with special null handling."
3+
title: C26477 USE_NULLPTR_NOT_CONSTANT
4+
ms.date: 04/29/2022
5+
ms.topic: reference
66
f1_keywords: ["C26477"]
77
helpviewer_keywords: ["C26477"]
88
ms.assetid: d5395efc-5eb2-4e82-9b45-fcd5ff4577bf
99
author: kylereedmsft
1010
ms.author: kylereed
11+
ms.custom: kr2b-contr-experiment
1112
---
1213
# C26477 USE_NULLPTR_NOT_CONSTANT
1314

docs/code-quality/c26486.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
---
2-
description: "Learn more about: C26486 LIFETIMES_FUNCTION_PRECONDITION_VIOLATION"
3-
title: C26486
4-
ms.date: 12/14/2018
5-
ms.topic: "conceptual"
2+
description: "Learn more about the C26486 LIFETIMES_FUNCTION_PRECONDITION_VIOLATION C++ Core Guidelines Checker warning. Don't pass an invalid pointer as a parameter."
3+
title: C26486 LIFETIMES_FUNCTION_PRECONDITION_VIOLATION
4+
ms.date: 04/29/2022
5+
ms.topic: reference
66
f1_keywords: ["C26486"]
77
helpviewer_keywords: ["C26486"]
88
ms.assetid: d5395efc-5eb2-4e82-9b45-fcd5ff4577bf
99
author: kylereedmsft
1010
ms.author: kylereed
11+
ms.custom: kr2b-contr-experiment
1112
---
1213
# C26486 LIFETIMES_FUNCTION_PRECONDITION_VIOLATION
1314

docs/cpp/tutorial-named-modules-cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ Module partitions make it easier to logically factor a large module. They can be
365365

366366
## Summary
367367

368-
In this tutorial, you've been introduced t the basics of C++20 modules. You've created a primary module interface, defined a module partition, and built a module implementation file. These files factor the module and present an API to the files that import it.
368+
In this tutorial, you've been introduced to the basics of C++20 modules. You've created a primary module interface, defined a module partition, and built a module implementation file. These files factor the module and present an API to the files that import it.
369369

370370
## See also
371371

docs/sanitizers/asan-error-examples.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Each error example provides source code and compilation instructions for a comma
2020

2121
- [Error: `calloc-overflow`](./error-calloc-overflow.md)
2222

23+
- [Error: `container-overflow`](./error-container-overflow.md)
24+
2325
- [Error: `double-free`](./error-double-free.md)
2426

2527
- [Error: `dynamic-stack-buffer-overflow`](./error-dynamic-stack-buffer-overflow.md)

docs/sanitizers/asan-known-issues.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "AddressSanitizer known issues"
33
description: "Technical description of the AddressSanitizer for Microsoft C/C++ known issues."
4-
ms.date: 03/02/2021
4+
ms.date: 04/15/2022
55
helpviewer_keywords: ["AddressSanitizer known issues"]
66
---
77

@@ -26,9 +26,11 @@ These options and functionality are incompatible with [`/fsanitize=address`](../
2626

2727
## Standard library support
2828

29-
The MSVC standard library (STL) isn't enlightened to understand the AddressSanitizer. AddressSanitizer exceptions raised in STL code do identify true bugs. However, they aren't as precise as they could be.
29+
The MSVC standard library (STL) is partially enlightened to understand the AddressSanitizer and provide additional checks. For more information, see [container-overflow error](./error-container-overflow.md).
3030

31-
This example demonstrates the lack of precision:
31+
When annotations are disabled or in versions without support, AddressSanitizer exceptions raised in STL code do still identify true bugs. However, they aren't as precise as they could be.
32+
33+
This example demonstrates the lack of precision and the benefits of enabling annotations:
3234

3335
```cpp
3436
// Compile with: cl /fsanitize=address /Zi
@@ -39,12 +41,14 @@ int main() {
3941
std::vector<int> v(10);
4042
v.reserve(20);
4143

42-
// Currently, MSVC ASan does NOT raise an exception here.
44+
// In versions prior to 17.2, MSVC ASan does NOT raise an exception here.
4345
// While this is an out-of-bounds write to 'v', MSVC ASan
4446
// ensures the write is within the heap allocation size (20).
47+
// With 17.2 and later, MSVC ASan will raise a 'container-overflow' exception:
48+
// ==18364==ERROR: AddressSanitizer: container-overflow on address 0x1263cb8a0048 at pc 0x7ff6466411ab bp 0x005cf81ef7b0 sp 0x005cf81ef7b8
4549
v[10] = 1;
4650

47-
// MSVC ASan DOES raise an exception here, as this write
51+
// Regardless of version, MSVC ASan DOES raise an exception here, as this write
4852
// is out of bounds from the heap allocation.
4953
v[20] = 1;
5054
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: "Error: container-overflow"
3+
description: "Source examples and live debug screenshots for container overflow errors."
4+
ms.date: 04/15/2022
5+
f1_keywords: ["container-overflow", "mismatch detected for 'annotate_vector'", "_DISABLE_VECTOR_ANNOTATION"]
6+
helpviewer_keywords: ["container-overflow error", "AddressSanitizer error container-overflow", "mismatch detected for 'annotate_vector'", "_DISABLE_VECTOR_ANNOTATION"]
7+
---
8+
9+
# Error: `container-overflow`
10+
11+
> Address Sanitizer Error: Container overflow
12+
13+
In Visual Studio 2022 version 17.2 and later, the MSVC standard library (STL) is partially enlightened to understand the AddressSanitizer. The following container types have inserted extra annotations to detect memory access issues:
14+
15+
| Standard container type | Disable annotations macro | Supported in version |
16+
|--|--|--|
17+
| `std::vector` | `_DISABLE_VECTOR_ANNOTATION` | Visual Studio 2022 17.2 |
18+
19+
When a standard type has annotations enabled, to avoid one-definition-rule (ODR) violations, each static library and object used to link the binary must also enable those annotations. Effectively, you must build those static libraries and objects with AddressSanitizer enabled. Mixing code with different annotation settings causes an error:
20+
21+
```Output
22+
my_static.lib(my_code.obj) : error LNK2038: mismatch detected for 'annotate_vector': value '0' doesn't match value '1' in main.obj
23+
```
24+
25+
To resolve this error, either disable annotations in all projects that use the corresponding macro, or build each project by using **`/fsanitize=address`** and annotations enabled. (Annotations are enabled by default.)
26+
27+
## Example: Access reserved memory in a `std::vector`
28+
29+
```cpp
30+
// Compile with: cl /EHsc /fsanitize=address /Zi
31+
#include <vector>
32+
33+
int main() {
34+
// Create a vector of size 10, but with a capacity of 20.
35+
std::vector<int> v(10);
36+
v.reserve(20);
37+
38+
// In versions prior to 17.2, MSVC ASan does NOT raise an exception here.
39+
// While this is an out-of-bounds write to 'v', MSVC ASan
40+
// ensures the write is within the heap allocation size (20).
41+
// With 17.2 and later, MSVC ASan will raise a 'container-overflow' exception:
42+
// ==18364==ERROR: AddressSanitizer: container-overflow on address 0x1263cb8a0048 at pc 0x7ff6466411ab bp 0x005cf81ef7b0 sp 0x005cf81ef7b8
43+
v[10] = 1;
44+
45+
// Regardless of version, MSVC ASan DOES raise an exception here, as this write
46+
// is out of bounds from the heap allocation.
47+
v[20] = 1;
48+
}
49+
```
50+
51+
To build and test this example, run the following commands in a Visual Studio 2022 version 17.2 or later [Developer command prompt](../build/building-on-the-command-line.md#developer_command_prompt_shortcuts) window:
52+
53+
```cmd
54+
cl /EHsc example1.cpp /fsanitize=address /Zi
55+
devenv /debugexe example1.exe
56+
```
57+
58+
### Error result of reserved memory access in a `std::vector`
59+
60+
:::image type="content" source="media/container-overflow-example-1.png" alt-text="Screenshot of debugger displaying container-overflow error in example 1." lightbox="media/container-overflow-example-1.png":::
61+
62+
## See also
63+
64+
[AddressSanitizer overview](./asan.md)\
65+
[AddressSanitizer known issues](./asan-known-issues.md)\
66+
[AddressSanitizer build and language reference](./asan-building.md)\
67+
[AddressSanitizer runtime reference](./asan-runtime.md)\
68+
[AddressSanitizer shadow bytes](./asan-shadow-bytes.md)\
69+
[AddressSanitizer cloud or distributed testing](./asan-offline-crash-dumps.md)\
70+
[AddressSanitizer debugger integration](./asan-debugger-integration.md)\
71+
[AddressSanitizer error examples](./asan-error-examples.md)
Loading

docs/sanitizers/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ items:
2727
href: ../sanitizers/error-allocation-size-too-big.md
2828
- name: "calloc-overflow error"
2929
href: ../sanitizers/error-calloc-overflow.md
30+
- name: "container-overflow error"
31+
href: ../sanitizers/error-container-overflow.md
3032
- name: "double-free error"
3133
href: ../sanitizers/error-double-free.md
3234
- name: "dynamic-stack-buffer-overflow error"

0 commit comments

Comments
 (0)