Skip to content

Commit 81ba1d7

Browse files
committed
Merging changes synced from https://github.com/MicrosoftDocs/cpp-docs-pr (branch live)
2 parents 80a9124 + d1505b4 commit 81ba1d7

File tree

6 files changed

+139
-1
lines changed

6 files changed

+139
-1
lines changed

docs/code-quality/c26800.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ms.author: sunnych
1010
---
1111
# C26800
1212

13-
> warning C26800: Use of a moved from object: \<lock>.
13+
> warning C26800: Use of a moved from object: \<object>.
1414
1515
Warning C26800 is triggered when variable is used after it has been moved from. A variable is considered moved from after it was passed to a function as rvalue reference. There are some legitimate exceptions for uses such as assignment, destruction, and some state resetting functions such as std::vector::clear.
1616

docs/code-quality/c26822.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: C26822
3+
description: "Describes the Microsoft C/C++ code analysis warning C26822, its causes, and how to address it."
4+
ms.date: 06/27/2022
5+
f1_keywords: ["C26822"]
6+
helpviewer_keywords: ["C26822"]
7+
---
8+
9+
# C26822: NULLPTR_DEREFERENCE
10+
11+
Dereferencing a null pointer is frequent problem in C and C++. We have a variety of checks to deal with such problems. See this [blog post](https://devblogs.microsoft.com/cppblog/improved-null-pointer-dereference-detection-in-visual-studio-2022-version-17-0-preview-4/) for a comparison. When the analysis engine deduces the value of a pointer to be null and sees a dereference to that pointer it will emit a `C26822` warning. You can also enable [C26823](../code-quality/c26823.md) for a stricter analysis. This check also supports [SAL annotations](../code-quality/understanding-sal.md) and [`gsl::not_null`](https://github.com/microsoft/GSL) to describe invariants of the code.
12+
13+
14+
## Example
15+
16+
```cpp
17+
void f(int *p) {
18+
    if (p == nullptr)
19+
     *p = 42; // warning: C26822
20+
}
21+
22+
void assign_to_gsl_notnull() {
23+
    int* p = nullptr;
24+
    auto q = gsl::make_not_null(p); // C26822 warning
25+
}
26+
```
27+
28+
To solve this warning, make sure there is no null pointer dereference in the code, potentially by adding null checks. In case the code was found to be correct, false positive findings can often be fixed by using `gsl::not_null` or SAL annotations. There are some examples how to use some of those annotations below:
29+
30+
```cpp
31+
_Notnull_ int *get_my_ptr();
32+
gsl::not_null<int *> get_my_ptr2();
33+
34+
void local_analysis(int *p) {
35+
    _Analysis_assume_(p != nullptr);
36+
    *p = 42;
37+
}
38+
39+
void local_analysis2(_In_ int *p) {
40+
    int a = *p;
41+
}
42+
```

docs/code-quality/c26823.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: C26823
3+
description: "Describes the Microsoft C/C++ code analysis warning C26823, its causes, and how to address it."
4+
ms.date: 06/27/2022
5+
f1_keywords: ["C26823"]
6+
helpviewer_keywords: ["C26823"]
7+
---
8+
9+
# C26823: NULLPTR_DEREFERENCE_MAYBE
10+
11+
Dereferencing a null pointer is frequent problem in C and C++. We have a variety of checks to deal with such problems. See this [blog post](https://devblogs.microsoft.com/cppblog/improved-null-pointer-dereference-detection-in-visual-studio-2022-version-17-0-preview-4/) for a comparison. When the analysis engine deduces the value of a pointer might be null and sees a dereference to that pointer it will emit a `C26823` warning. You can enable [C26822](../code-quality/c26822.md) only for a more permissive analysis. This check also supports [SAL annotations](../code-quality/understanding-sal.md) and [`gsl::not_null`](https://github.com/microsoft/GSL) to describe invariants of the code.
12+
13+
14+
## Example
15+
16+
```cpp
17+
void invalidate(int **pp);
18+
void condition_null_dereference_invalidated(int* p)
19+
{
20+
if (p)
21+
return;
22+
23+
invalidate(&p);
24+
// The call above could reset the value of `p`, thus the low confidence warning.
25+
*p = 5; // warning: C26823
26+
}
27+
```
28+
29+
To solve this warning, make sure there is no null pointer dereference in the code, potentially by adding null checks. In case the code was found to be correct, false positive findings can often be fixed by using `gsl::not_null` or SAL annotations. There are some examples how to use some of those annotations below:
30+
31+
```cpp
32+
_Notnull_ int *get_my_ptr();
33+
gsl::not_null<int *> get_my_ptr2();
34+
35+
void local_analysis(int *p) {
36+
    _Analysis_assume_(p != nullptr);
37+
    *p = 42;
38+
}
39+
40+
void local_analysis2(_In_ int *p) {
41+
    int a = *p;
42+
}
43+
```

docs/code-quality/c26824.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: C26824
3+
description: "Describes the Microsoft C/C++ code analysis warning C26824, its causes, and how to address it."
4+
ms.date: 06/27/2022
5+
f1_keywords: ["C26824"]
6+
helpviewer_keywords: ["C26824"]
7+
---
8+
9+
# C26824: NULLPTR_POSTCONDITION_VIOLATION
10+
11+
Dereferencing a null pointer is frequent problem in C and C++. We have a variety of checks to deal with such problems. See this [blog post](https://devblogs.microsoft.com/cppblog/improved-null-pointer-dereference-detection-in-visual-studio-2022-version-17-0-preview-4/) for a comparison. When the analysis engine sees a null pointer returned from a function that has a contract forbidding such operation, it will emit a `C26824` warning. You can also enable [C26825](../code-quality/c26825.md) for a stricter analysis. This check only works on functions annotated using [SAL annotations](../code-quality/understanding-sal.md).
12+
13+
14+
## Example
15+
16+
```cpp
17+
void postcondition_conditional(bool b, _When_(b == true, _Outptr_) int** p) {
18+
    if (b == true)
19+
        *p = nullptr; // C26824 warning
20+
}
21+
```
22+
23+
To solve this warning, make sure there is no null pointer returned from the annotated function or change the annotations to reflect the behavior of the function.

docs/code-quality/c26825.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: C26825
3+
description: "Describes the Microsoft C/C++ code analysis warning C26825, its causes, and how to address it."
4+
ms.date: 06/27/2022
5+
f1_keywords: ["C26825"]
6+
helpviewer_keywords: ["C26825"]
7+
---
8+
9+
# C26825: NULLPTR_POSTCONDITION_VIOLATION_MAYBE
10+
11+
Dereferencing a null pointer is frequent problem in C and C++. We have a variety of checks to deal with such problems. See this [blog post](https://devblogs.microsoft.com/cppblog/improved-null-pointer-dereference-detection-in-visual-studio-2022-version-17-0-preview-4/) for a comparison. When the analysis engine sees a potentially null pointer returned from a function that has a contract forbidding such operation, it will emit a `C26825` warning. You can enable [C26824](../code-quality/c26824.md) only for a more permissive analysis. This check only works on functions annotated using [SAL annotations](../code-quality/understanding-sal.md).
12+
13+
14+
## Example
15+
16+
```cpp
17+
void postcondition_conditional(int *q, _Outptr_ int** p) {
18+
*p = q; // C26825 warning
19+
}
20+
```
21+
22+
To solve this warning, make sure there is no null pointer returned from the annotated function or change the annotations to reflect the behavior of the function.

docs/code-quality/toc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,14 @@ items:
583583
href: ../code-quality/c26811.md
584584
- name: C26813
585585
href: ../code-quality/c26813.md
586+
- name: C26822
587+
href: ../code-quality/c26822.md
588+
- name: C26823
589+
href: ../code-quality/c26823.md
590+
- name: C26824
591+
href: ../code-quality/c26824.md
592+
- name: C26825
593+
href: ../code-quality/c26825.md
586594
- name: C26826
587595
href: ../code-quality/c26826.md
588596
- name: C26827

0 commit comments

Comments
 (0)