Skip to content

Commit 9a61c7d

Browse files
authored
Merge pull request #2751 from corob-msft/cr-2020-C6011
Fix 2020: unclear C6011 text
2 parents ec4490f + 2b36e7f commit 9a61c7d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

docs/code-quality/c6011.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: C6011
3-
ms.date: 11/04/2016
3+
description: "Reference for Visual Studio C++ code analysis warning C6011."
4+
ms.date: 03/23/2020
45
ms.topic: reference
56
f1_keywords: ["C6011"]
67
helpviewer_keywords: ["C6011"]
@@ -10,11 +11,11 @@ ms.assetid: 54b7bc2b-b8f5-43fc-a9a3-8189b03f249a
1011

1112
> warning C6011: dereferencing NULL pointer \<name>
1213
13-
This warning indicates that a null pointer is being dereferenced. If the pointer value is invalid, the result is undefined.
14+
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.
1415

1516
## Example
1617

17-
The following code generates this warning because a call to malloc might return null if there is insufficient memory available:
18+
The following code generates this warning because a call to `malloc` might return null if insufficient memory is available:
1819

1920
```cpp
2021
#include <malloc.h>
@@ -29,7 +30,7 @@ void f( )
2930
}
3031
```
3132
32-
To correct this warning, examine the pointer for null value as shown in the following code:
33+
To correct this warning, examine the pointer for a null value as shown in the following code:
3334
3435
```cpp
3536
#include <malloc.h>
@@ -46,7 +47,7 @@ void f( )
4647
}
4748
```
4849

49-
You must allocate memory inside the function whose parameters are annotated by using the Null property in a Pre condition before dereferencing the parameter. The following code generates warning C6011 because an attempt is made to dereference a null pointer (`pc`) inside the function without first allocating memory:
50+
Functions may have parameters annotated by using the `Null` property in a `Pre` condition. Allocate memory inside these functions before you dereference the parameter. The following code generates warning C6011 because an attempt is made to dereference a null pointer (`pc`) inside the function without first allocating memory:
5051

5152
```cpp
5253
#include <sal.h>
@@ -58,7 +59,7 @@ void f([Pre(Null=Yes)] char* pc)
5859
}
5960
```
6061
61-
The use of malloc and free have many pitfalls in terms of memory leaks and exceptions. To avoid these kinds of leaks and exception problems altogether, use the mechanisms that are provided by the C++ Standard Template Library (STL). These include [shared_ptr](/cpp/standard-library/shared-ptr-class), [unique_ptr](/cpp/standard-library/unique-ptr-class), and [vector](/cpp/standard-library/vector). For more information, see [Smart Pointers](/cpp/cpp/smart-pointers-modern-cpp) and [C++ Standard Library](/cpp/standard-library/cpp-standard-library-reference).
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](/cpp/standard-library/shared-ptr-class), [unique_ptr](/cpp/standard-library/unique-ptr-class), and [vector](/cpp/standard-library/vector). For more information, see [Smart Pointers](/cpp/cpp/smart-pointers-modern-cpp) and [C++ Standard Library](/cpp/standard-library/cpp-standard-library-reference).
6263
6364
## See also
6465

0 commit comments

Comments
 (0)