You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
14
15
15
16
## Example
16
17
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:
18
19
19
20
```cpp
20
21
#include<malloc.h>
@@ -29,7 +30,7 @@ void f( )
29
30
}
30
31
```
31
32
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:
33
34
34
35
```cpp
35
36
#include <malloc.h>
@@ -46,7 +47,7 @@ void f( )
46
47
}
47
48
```
48
49
49
-
You must allocate memory inside the function whose parameters are annotated by using the Null property in a Pre conditionbefore 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:
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).
0 commit comments