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
{{ message }}
Repository navigation
Commit 5906e8c
Browse filesBrowse the repository at this point in the historyBrowse files
> warning C6064: missing integer argument to \<function> corresponding to conversion specifier \<number>
12
+
> Missing integer argument to '*function-name*' corresponding to conversion specifier '*number*'
13
13
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.
15
15
16
-
## Example
16
+
## Remarks
17
17
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.
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:
32
25
33
26
```cpp
34
-
#include <string.h>
35
-
void f( )
27
+
voidf()
36
28
{
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
41
32
}
42
33
```
43
34
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:
> 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*'
13
13
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.
15
15
16
-
## Example
16
+
## Remarks
17
17
18
-
The following code generates this warning:
18
+
This defect can lead to crashes, in addition to potentially incorrect output.
> 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*'
13
13
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.
15
15
16
-
## Example
17
-
18
-
The following code generates this warning:
16
+
## Remarks
19
17
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.
> warning C6279: \<variable> is allocated with scalar new, deleted with array delete []
12
+
> '*variable-name*' is allocated with scalar new, deleted with array delete []
13
13
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`.
15
15
16
-
There are at least three reasons that this is likely to cause problems:
16
+
## Remarks
17
17
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.
19
19
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).
21
21
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
23
23
24
24
## Example
25
25
26
-
The following code generates this warning:
26
+
The following code generates this warning. `A` is allocated using `new` but deleted using `delete[]`:
27
27
28
28
```cpp
29
29
classA
@@ -39,7 +39,7 @@ void f ( )
39
39
}
40
40
```
41
41
42
-
To correct this warning, use the following code:
42
+
The following code remediates this warning by using `delete` instead:
43
43
44
44
```cpp
45
45
void f( )
@@ -50,8 +50,6 @@ void f( )
50
50
}
51
51
```
52
52
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).
> warning C6280: \<variable> is allocated with \<function>, but deleted with \<function>
12
+
> '*variable-name*' is allocated with '*function-name', but deleted with '*function-name*'
13
13
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.
15
15
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
17
23
18
24
## Example
19
25
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`:
21
27
22
28
```cpp
23
29
// cl.exe /analyze /c /EHsc /nologo /W4
@@ -34,7 +40,7 @@ void f(int arraySize)
34
40
}
35
41
```
36
42
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`:
38
44
39
45
```cpp
40
46
// cl.exe /analyze /c /EHsc /nologo /W4
@@ -51,9 +57,11 @@ void f(int arraySize)
51
57
}
52
58
```
53
59
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).
55
63
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`:
0 commit comments