Skip to content

Commit 5906e8c

Browse files
authored
Merge pull request MicrosoftDocs#4516 from MugBergerFries/patch-12
Updated Reliability MinBar Warnings (WIP)
2 parents 46cb683 + 4bf1b64 commit 5906e8c

File tree

9 files changed

+151
-198
lines changed

9 files changed

+151
-198
lines changed

docs/code-quality/c6064.md

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,48 @@
11
---
22
description: "Learn more about: C6064"
33
title: C6064
4-
ms.date: 11/04/2016
4+
ms.date: 09/14/2022
55
ms.topic: reference
6-
f1_keywords: ["C6064"]
6+
f1_keywords: ["C6064", "MISSING_INTEGER_ARGUMENT_TO_FORMAT_FUNCTION", "__WARNING_MISSING_INTEGER_ARGUMENT_TO_FORMAT_FUNCTION"]
77
helpviewer_keywords: ["C6064"]
88
ms.assetid: d8f126aa-b093-440e-820f-65b8e6cffaba
99
---
10-
# C6064
10+
# Warning C6064
1111

12-
> warning C6064: missing integer argument to \<function> corresponding to conversion specifier \<number>
12+
> Missing integer argument to '*function-name*' corresponding to conversion specifier '*number*'
1313
14-
This warning indicates that not enough arguments are being provided to match a format string and one of the missing arguments is an integer. This defect can cause incorrect output.
14+
This warning indicates that not enough arguments are being provided to match a format string and one of the missing arguments is an integer.
1515

16-
## Example
16+
## Remarks
1717

18-
The following code generates this warning because an incorrect number of arguments were used in call to `sprintf` and the missing argument was an integer:
18+
This defect is likely to cause incorrect output and, in more dangerous cases, can lead to stack overflow.
1919

20-
```cpp
21-
#include <string.h>
22-
void f( )
23-
{
24-
char buff[15];
25-
char *string="Hello, World";
20+
Code analysis name: MISSING_INTEGER_ARGUMENT_TO_FORMAT_FUNCTION
2621

27-
sprintf(buff,"%s %d", string);
28-
}
29-
```
22+
## Example
3023

31-
To correct this warning, specify missing arguments as shown in the following code:
24+
The following code generates this warning because an incorrect number of arguments were used in the call to `sprintf_s` and the missing argument was an integer. Had the unsafe function `sprintf` been used instead of the safer variant `sprintf_s`, this code would likely cause a stack overflow instead of just an unexpected output:
3225

3326
```cpp
34-
#include <string.h>
35-
void f( )
27+
void f()
3628
{
37-
char buff[15];
38-
char *string = "Hello, World";
39-
40-
sprintf(buff,"%s %d",string, strlen(string));
29+
char buff[8];
30+
char *string="Hello";
31+
sprintf_s(buff, sizeof(buff), "%s %d", string); // Attempts to print "Hello 256" or approximate, which cannot fit in the 8 char buffer. This would overflow if sprintf had been used instead
4132
}
4233
```
4334

44-
The following code uses safe string manipulation function, `sprintf_s` to correct this warning:
35+
To correct this warning, specify missing arguments as shown in the following code:
4536

4637
```cpp
47-
#include <string.h>
48-
void f( )
38+
void f()
4939
{
50-
char buff[15];
51-
char *string="Hello World";
52-
53-
sprintf_s(buff,sizeof(buff),"%s %d", string, strlen(string));
40+
char buff[8];
41+
char *string = "Hello";
42+
sprintf_s(buff, sizeof(buff), "%s %d", string, strlen(string));
5443
}
5544
```
5645

5746
## See also
5847

59-
[sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l](../c-runtime-library/reference/sprintf-s-sprintf-s-l-swprintf-s-swprintf-s-l.md)
48+
[sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l](/cpp/c-runtime-library/reference/sprintf-s-sprintf-s-l-swprintf-s-swprintf-s-l)

docs/code-quality/c6270.md

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,47 @@
11
---
22
description: "Learn more about: C6270"
33
title: C6270
4-
ms.date: 11/04/2016
4+
ms.date: 09/14/2022
55
ms.topic: reference
6-
f1_keywords: ["C6270"]
6+
f1_keywords: ["C6270", "MISSING_FLOAT_ARGUMENT_TO_FORMAT_FUNCTION", "__WARNING_MISSING_FLOAT_ARGUMENT_TO_FORMAT_FUNCTION"]
77
helpviewer_keywords: ["C6270"]
88
ms.assetid: 34467f6e-98cf-489c-ae5e-c08a744d86c3
99
---
10-
# C6270
10+
# Warning C6270
1111

12-
> warning C6270: missing float argument to \<function>: add a float argument corresponding to conversion specifier \<number>
12+
> Missing float argument to '*function-name*': add a float argument corresponding to conversion specifier '*number*'
1313
14-
This warning indicates that not enough arguments are being provided to match a format string; at least one of the missing arguments is a floating-point number. This defect can lead to crashes, in addition to potentially incorrect output.
14+
This warning indicates that not enough arguments are being provided to match a format string; at least one of the missing arguments is a floating-point number.
1515

16-
## Example
16+
## Remarks
1717

18-
The following code generates this warning:
18+
This defect can lead to crashes, in addition to potentially incorrect output.
1919

20-
```cpp
21-
#include <stdio.h>
22-
#include <string.h>
20+
Code analysis name: MISSING_FLOAT_ARGUMENT_TO_FORMAT_FUNCTION
2321

24-
void f()
25-
{
26-
char buff [25];
27-
sprintf(buff,"%s %f","pi:");
28-
}
29-
```
22+
## Example
3023

31-
To correct this warning, pass the missing argument as shown in the following code:
24+
The following code generates this warning. `sprintf_s` expects a second float argument as denoted by `%f` but none is provided:
3225

3326
```cpp
34-
#include <stdio.h>
35-
#include <string.h>
36-
3727
void f()
3828
{
39-
char buff [25];
40-
sprintf(buff,"%s %f","pi:",3.1415);
29+
char buff [25];
30+
sprintf_s(buff, sizeof(buff), "%s %f", "pi: ");
4131
}
4232
```
4333

44-
The following sample code uses the safe string manipulation function, `sprintf_s`, to correct this warning:
34+
To correct this warning, pass the missing float argument as shown in the following code:
4535

4636
```cpp
47-
#include <stdio.h>
48-
#include <string.h>
49-
5037
void f()
5138
{
52-
char buff [25];
53-
sprintf_s( buff, 25,"%s %f", "pi:",3.1415 );
39+
char buff [25];
40+
sprintf_s(buff, sizeof(buff), "%s %f", "pi: ", 3.14159);
5441
}
5542
```
5643

5744
## See also
5845

59-
[sprintf, _sprintf_l, swprintf, _swprintf_l, \__swprintf_l](../c-runtime-library/reference/sprintf-sprintf-l-swprintf-swprintf-l-swprintf-l.md)
46+
[sprintf, _sprintf_l, swprintf, _swprintf_l, \__swprintf_l](../c-runtime-library/reference/sprintf-sprintf-l-swprintf-swprintf-l-swprintf-l.md)\
47+
[sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l](/cpp/c-runtime-library/reference/sprintf-s-sprintf-s-l-swprintf-s-swprintf-s-l)

docs/code-quality/c6272.md

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,44 @@
11
---
22
description: "Learn more about: C6272"
33
title: C6272
4-
ms.date: 11/04/2016
4+
ms.date: 09/15/2022
55
ms.topic: reference
6-
f1_keywords: ["C6272"]
6+
f1_keywords: ["C6272", "NON_FLOAT_ARGUMENT_TO_FORMAT_FUNCTION", "__WARNING_NON_FLOAT_ARGUMENT_TO_FORMAT_FUNCTION"]
77
helpviewer_keywords: ["C6272"]
88
ms.assetid: b63937ac-fbb2-45ec-936a-641c156e6355
99
---
10-
# C6272
10+
# Warning C6272
1111

12-
> warning C6272: non-float passed as argument \<number> when float is required in call to \<function>
12+
> Non-float passed as argument '*number*' when float is required in call to '*function-name*'
1313
14-
This warning indicates that the format string specifies that a float is required, for example, a `%f` or `%g` specification for `printf,` but a non-float such as an integer or string is being passed. This defect is likely to result in incorrect output; however, in certain circumstances it could result in a crash.
14+
This warning indicates that the format string specifies that a float is required, for example, a `%f` or `%g` specification for `printf,` but a non-float such as an integer or string is being passed.
1515

16-
## Example
17-
18-
The following code generates this warning:
16+
## Remarks
1917

20-
```cpp
21-
#include <stdio.h>
22-
#include <string.h>
18+
This defect is likely to result in incorrect output and, in certain circumstances, could result in a crash.
2319

24-
void f()
25-
{
26-
char buff[5];
27-
int i=5;
20+
Code analysis name: NON_FLOAT_ARGUMENT_TO_FORMAT_FUNCTION
2821

29-
sprintf(buff,"%s %f","a",i);
30-
}
31-
```
22+
## Example
3223

33-
To correct this warning, use `%i` instead of `%f` specification as shown in the following code:
24+
The following code generates this warning. `%f` indicates a float is expected, but the integer `i` is passed instead:
3425

3526
```cpp
36-
#include <stdio.h>
37-
#include <string.h>
38-
3927
void f()
4028
{
41-
char buff[5];
42-
int i=5;
43-
44-
sprintf(buff,"%s %i","a",i);
29+
char buff[5];
30+
int i=5;
31+
sprintf_s(buff, sizeof(buff), "%s %f", "a", i);
4532
}
4633
```
4734

48-
The following code uses the safe string manipulation function, `sprintf_s`, to correct this warning:
35+
To correct this warning, use `%i` instead of `%f` specification as shown in the following code:
4936

5037
```cpp
51-
#include <stdio.h>
52-
#include <string.h>
53-
5438
void f()
5539
{
56-
char buff[5];
57-
int i=5;
58-
59-
sprintf_s(buff,5,"%s %i","a",i); // safe version
40+
char buff[5];
41+
int i=5;
42+
sprintf_s(buff, sizeof(buff), "%s %i", "a", i);
6043
}
6144
```
62-
63-
## See also
64-
65-
[sprintf, _sprintf_l, swprintf, _swprintf_l, \__swprintf_l](../c-runtime-library/reference/sprintf-sprintf-l-swprintf-swprintf-l-swprintf-l.md)

docs/code-quality/c6279.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
---
22
description: "Learn more about: C6279"
33
title: C6279
4-
ms.date: 11/04/2016
4+
ms.date: 09/15/2022
55
ms.topic: reference
6-
f1_keywords: ["C6279"]
6+
f1_keywords: ["C6279", "NEW_ARRAY_DELETE_MISMATCH", "__WARNING_NEW_ARRAY_DELETE_MISMATCH"]
77
helpviewer_keywords: ["C6279"]
88
ms.assetid: 0af88b58-35df-456f-8c02-e8eeffe3b7de
99
---
10-
# C6279
10+
# Warning C6279
1111

12-
> warning C6279: \<variable> is allocated with scalar new, deleted with array delete []
12+
> '*variable-name*' is allocated with scalar new, deleted with array delete []
1313
14-
This warning appears only in C++ code and indicates that the calling function has inconsistently allocated memory with the scalar **`new`** operator, but freed it with the array **delete []** operator. If memory is allocated with scalar **`new`**, it should typically be freed with scalar **`delete`**.
14+
This warning appears only in C++ code and indicates that the calling function has inconsistently allocated memory with the scalar `new` operator, but freed it with the array `delete[]` operator. If memory is allocated with scalar `new`, it should typically be freed with scalar `delete`.
1515

16-
There are at least three reasons that this is likely to cause problems:
16+
## Remarks
1717

18-
- The constructors for the individual objects in the array are not invoked, although the destructors are.
18+
The exact ramifications of this defect are difficult to predict. It might cause random behavior or crashes due to usage of uninitialized memory as constructors aren't invoked. Or, it might cause memory allocations and crashes in situations where operators have been overridden. The analysis tool doesn't currently distinguish between these situations.
1919

20-
- If global (or class-specific) **operator new** and **operator delete** are not compatible with **operator new[]** and **operator delete[]**, unexpected results are likely to occur.
20+
To avoid these kinds of allocation problems altogether, use the mechanisms that are provided by the C++ Standard Template 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).
2121

22-
The exact ramifications of this defect are difficult to predict. It might cause random behavior or crashes due to usage of uninitialized memory because constructors are not invoked. Or, it might cause memory allocations and crashes in situations where operators have been overridden. In rare cases, the mismatch might be unimportant. Analysis tool does not currently distinguish between these situations.
22+
Code analysis name: NEW_ARRAY_DELETE_MISMATCH
2323

2424
## Example
2525

26-
The following code generates this warning:
26+
The following code generates this warning. `A` is allocated using `new` but deleted using `delete[]`:
2727

2828
```cpp
2929
class A
@@ -39,7 +39,7 @@ void f ( )
3939
}
4040
```
4141
42-
To correct this warning, use the following code:
42+
The following code remediates this warning by using `delete` instead:
4343
4444
```cpp
4545
void f( )
@@ -50,8 +50,6 @@ void f( )
5050
}
5151
```
5252

53-
To avoid these kinds of allocation problems altogether, use the mechanisms that are provided by the C++ Standard Template 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).
54-
5553
## See also
5654

5755
- [C6014](../code-quality/c6014.md)

docs/code-quality/c6280.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
---
22
description: "Learn more about: C6280"
33
title: C6280
4-
ms.date: 11/04/2016
4+
ms.date: 09/15/2022
55
ms.topic: reference
6-
f1_keywords: ["C6280"]
6+
f1_keywords: ["C6280", "MEMORY_ALLOCATION_MISMATCH", "__WARNING_MEMORY_ALLOCATION_MISMATCH"]
77
helpviewer_keywords: ["C6280"]
88
ms.assetid: b91f2966-0876-4c9b-843a-e142f35be864
99
---
10-
# C6280
10+
# Warning C6280
1111

12-
> warning C6280: \<variable> is allocated with \<function>, but deleted with \<function>
12+
> '*variable-name*' is allocated with '*function-name', but deleted with '*function-name*'
1313
14-
This warning indicates that the calling function has inconsistently allocated memory by using a function from one memory allocation family and freed it by using a function from another memory allocation family. 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).
14+
This warning indicates that the calling function has inconsistently allocated memory by using a function from one family and freed it by using a function from another.
1515

16-
For example, this warning would be produced if memory is allocated by using `malloc` but freed by using `GlobalFree` or **`delete`**. In the specific cases of mismatches between array `new[]` and scalar **`delete`**, more precise warnings are reported instead of this one.
16+
## Remarks
17+
18+
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).
19+
20+
For example, this warning would be produced if memory is allocated by using `malloc` but freed by using `GlobalFree` or `delete`. In the specific cases of mismatches between array `new[]` and scalar `delete`, more precise warnings are reported instead of this one.
21+
22+
Code analysis name: MEMORY_ALLOCATION_MISMATCH
1723

1824
## Example
1925

20-
The following sample code generates this warning.
26+
The following sample code generates this warning. `pInt` is allocated using `calloc` but is freed using the mismatched function `delete`:
2127

2228
```cpp
2329
// cl.exe /analyze /c /EHsc /nologo /W4
@@ -34,7 +40,7 @@ void f(int arraySize)
3440
}
3541
```
3642
37-
To correct this warning, use this code:
43+
The following code remediates this warning by using the deallocation function `free`, the match to `calloc`:
3844
3945
```cpp
4046
// cl.exe /analyze /c /EHsc /nologo /W4
@@ -51,9 +57,11 @@ void f(int arraySize)
5157
}
5258
```
5359

54-
Different API definitions can use different heaps. For example, `GlobalAlloc` uses the system heap, and `free` uses the process heap. This is likely to cause memory corruptions and crashes.
60+
Different API definitions can use different heaps. For example, `GlobalAlloc` uses the system heap, and `free` uses the process heap. This issue is likely to cause memory corruptions and crashes.
61+
62+
These inconsistencies apply to the `new`/`delete` and `malloc`/`free` memory allocation mechanisms. To avoid these kinds of potential inconsistencies altogether, use the mechanisms that are provided by the C++ Standard Template 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).
5563

56-
These inconsistencies apply to the **`new`**/**`delete`** and `malloc`/`free` memory allocation mechanisms. To avoid these kinds of potential inconsistencies altogether, use the mechanisms that are provided by the C++ Standard Template 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).
64+
The following code avoids this problem entirely by using `unique_ptr`:
5765

5866
```cpp
5967
// cl.exe /analyze /c /EHsc /nologo /W4

0 commit comments

Comments
 (0)