Skip to content

Commit 8888feb

Browse files
Merge pull request #4480 from MicrosoftDocs/main638151898919069043sync_temp
For protected CLA branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 5531848 + d6364ad commit 8888feb

File tree

14 files changed

+181
-102
lines changed

14 files changed

+181
-102
lines changed

docs/code-quality/c28308.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
11
---
22
description: "Learn more about: Warning C28308"
33
title: Warning C28308
4-
ms.date: 11/04/2016
5-
f1_keywords: ["C28308"]
4+
ms.date: 03/07/2023
5+
f1_keywords: ["C28308", "BAD_FORMAT_ARGUMENT_POSITION", "__WARNING_BAD_FORMAT_ARGUMENT_POSITION"]
66
helpviewer_keywords: ["C28308"]
7-
ms.assetid: 2be46de3-844e-4cd6-a97f-d5c12ac9dc31
87
---
98
# Warning C28308
109

1110
> The format list argument position specified by the annotation is incorrect.
1211
13-
The format list argument position must be either a parameter name, or an integer offset that's in the parameter list, or zero.
12+
## Remarks
1413

15-
The second parameter to `IsFormatString2` (`where`) can be in one of two forms:
14+
This warning indicates a `_*_format_strings_param(position)` SAL annotation is specifying an invalid position for the first parameter to the format string. The annotation helps the checker verify `printf` style formatting strings passed to the function. Other format string validity checks that rely on this annotation won't run as a result of this warning.
1615

17-
- A parameter name, which is taken as the first argument to the format string.
16+
The `_*_format_strings_param(position)` SAL annotation is attached to the formatting string argument. `position` must be in one of these forms:
1817

19-
- An offset (`n`) relative to the format-string parameter.
18+
- An identifier, which is taken as the first argument to the format string. When the identifier isn't the name of a parameter to the function, a warning is emitted.
19+
- A positive integer offset relative to the format-string parameter where `1` is the next parameter. When the offset is out of bounds for the parameters, a warning is emitted.
20+
- The value `0`, which is interpreted as the `...` parameter. When the function isn't variadic, a warning is emitted.
2021

21-
In the second form, the first format-string parameter is the `n`-th argument after the format string. If `n` is zero, an ellipsis is specified as the parameter. Specifying an offset of zero without specifying the ellipsis as the first format-string parameter will cause an error.
22+
One limitation of this check, is that it's run at the function call site and not at the declaration. This limitation is a side effect of the lazy evaluation of SAL annotations.
23+
24+
## Examples
25+
26+
In this example, there's a specialized function for logging coordinates. The params annotation specifies the `...` parameter, which doesn't exist.
27+
28+
```cpp
29+
void LogCoordinate(_Printf_format_string_params_(0) _In_ char *format, int x, int y);
30+
31+
void func(int x, int y)
32+
{
33+
LogCoordinate("(%d, %d)", x, y);
34+
}
35+
```
36+
37+
This issue is fixed by changing the annotated position to `x` or `1`. To determine the correct value for your code, check the behavior of the called function.
38+
39+
```cpp
40+
void LogCoordinate(_Printf_format_string_params_(1) _In_ char *format, int x, int y);
41+
42+
void func(int x, int y)
43+
{
44+
LogCoordinate("(%d, %d)", x, y);
45+
}
46+
```
47+
48+
## See also
49+
50+
[Annotating function parameters and return values](./annotating-function-parameters-and-return-values.md)

docs/code-quality/c6063.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
description: "Learn more about: Warning C6063"
33
title: Warning C6063
4-
ms.date: 10/04/2022
4+
ms.date: 2/22/2023
55
f1_keywords: ["C6063", "MISSING_STRING_ARGUMENT_TO_FORMAT_FUNCTION", "__WARNING_MISSING_STRING_ARGUMENT_TO_FORMAT_FUNCTION"]
66
helpviewer_keywords: ["C6063"]
7-
ms.assetid: 9a4b0684-6c13-4242-a1ab-97980b6cfdc4
87
---
98
# Warning C6063
109

@@ -21,18 +20,18 @@ Code analysis name: `MISSING_STRING_ARGUMENT_TO_FORMAT_FUNCTION`
2120
The following code generates this warning:
2221

2322
```cpp
24-
#include <string.h>
23+
#include <stdio.h>
2524
void f( )
2625
{
2726
char buff[15];
2827
sprintf(buff, "%s %s", "Hello, World!");
2928
}
3029
```
3130
32-
To correct this warning, provide the required arguments as shown in the following code:
31+
To correct this warning, remove the unused format specifier or provide the required arguments as shown in the following code:
3332
3433
```cpp
35-
#include <string.h>
34+
#include <stdio.h>
3635
void f( )
3736
{
3837
char buff[15];
@@ -43,7 +42,7 @@ void f( )
4342
The following code corrects this warning using safe string manipulation function:
4443

4544
```cpp
46-
#include <string.h>
45+
#include <stdio.h>
4746
void f( )
4847
{
4948
char buff[15];
@@ -53,4 +52,5 @@ void f( )
5352
5453
## See also
5554
55+
[Format specification syntax: printf and wprintf functions](../c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.md)\
5656
[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)

docs/code-quality/c6065.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
description: "Learn more about: Warning C6065"
3+
title: Warning C6065
4+
ms.date: 2/22/2023
5+
f1_keywords: ["C6065", "MISSING_COUNTED_STRING_ARGUMENT_TO_FORMAT_FUNCTION", "__MISSING_COUNTED_STRING_ARGUMENT_TO_FORMAT_FUNCTION"]
6+
helpviewer_keywords: ["C6065"]
7+
---
8+
# Warning C6065
9+
10+
> warning C6065: Missing pointer to '*string type*' argument to '*function*' that corresponds to argument 'number'
11+
12+
## Remarks
13+
14+
This warning indicates that there's a mismatch between the format specifiers in a string and the types of the associated parameters. The format specifier indicates that at least one of the mismatched arguments should be a pointer to a counted string such as `UNICODE_STRING` or `ANSI_STRING` but it not. This defect can cause crashes, buffer overflows, and potentially incorrect output.
15+
16+
To fix this warning, determine if the format specifier or the argument matches the intended behavior and modify the other to match. When modifying the format specifier for a counted string, it's recommended to explicitly use the size prefix such as `%wZ` or `%hZ` rather than `%Z` due to compatibility issues between C runtimes (CRT). For more information on CRT compatibility, see the `%Z` row in the [Type field characters documentation](../c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.md#type-field-characters).
17+
18+
Code analysis name: `MISSING_COUNTED_STRING_ARGUMENT_TO_FORMAT_FUNCTION`
19+
20+
## Example
21+
22+
The following code generates this warning because the value passed to printf isn't a pointer:
23+
24+
```cpp
25+
int PrintDiagnostic(UNICODE_STRING u)
26+
{
27+
printf("%wZ", u);
28+
}
29+
```
30+
31+
In this example, we fix the warning by changing the passed in parameter to be a pointer:
32+
33+
```cpp
34+
int PrintDiagnostic(UNICODE_STRING u)
35+
{
36+
printf("%wZ", &u);
37+
}
38+
```
39+
40+
## See also
41+
42+
[format specification syntax: printf and wprintf functions](../c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.md)\
43+
[`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)\
44+
[`UNICODE_STRING`](/windows/win32/api/ntdef/ns-ntdef-_unicode_string)\
45+
[`ANSI_STRING/_STRING`](/windows/win32/api/ntdef/ns-ntdef-string)\
46+
[C4313](../error-messages/compiler-warnings/compiler-warning-level-1-c4313.md)

docs/code-quality/c6066.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
description: "Learn more about: Warning C6066"
33
title: Warning C6066
4-
ms.date: 10/04/2022
4+
ms.date: 3/02/2023
55
f1_keywords: ["C6066", "NON_POINTER_ARGUMENT_TO_FORMAT_FUNCTION", "__WARNING_NON_POINTER_ARGUMENT_TO_FORMAT_FUNCTION"]
66
helpviewer_keywords: ["C6066"]
7-
ms.assetid: f03c9cf1-d8eb-4731-a66a-da7c924616fb
87
---
98
# Warning C6066
109

@@ -32,8 +31,7 @@ void f( )
3231

3332
void g( int i )
3433
{
35-
int result;
36-
result = scanf( "%d", i ); // warning C6066
34+
int result = scanf( "%d", i ); // warning C6066
3735
// code ...
3836
}
3937
```
@@ -47,15 +45,12 @@ To correct this warning, the following code passes correct parameters to the `sp
4745
void f( )
4846
{
4947
char buff[MAX];
50-
5148
sprintf( buff, "%s %p %d", "Hello, World!", buff, MAX ); // pass buff
5249
// code ...
5350
}
5451
void g( int i )
5552
{
56-
int result;
57-
// code ...
58-
result = scanf( "%d", &i ); // pass the address of i
53+
int result = scanf( "%d", &i ); // pass the address of i
5954
// code ...
6055
}
6156
```
@@ -66,15 +61,12 @@ The following code uses safe string manipulation functions `sprintf_s` and `scan
6661
void f( )
6762
{
6863
char buff[MAX];
69-
7064
sprintf_s( buff, sizeof(buff), "%s %p %d", "Hello, World!", buff, MAX );
7165
// code ...
7266
}
7367
void g( int i )
7468
{
75-
int result;
76-
// code ...
77-
result = scanf_s( "%d", &i );
69+
int result = scanf_s( "%d", &i );
7870
// code ...
7971
}
8072
```
@@ -83,5 +75,8 @@ This warning is typically reported because an integer has been used for a `%p` f
8375
8476
## See also
8577
86-
- [`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)
87-
- [`scanf_s`, `_scanf_s_l`, `wscanf_s`, `_wscanf_s_l`](../c-runtime-library/reference/scanf-s-scanf-s-l-wscanf-s-wscanf-s-l.md)
78+
[Format specification syntax: printf and wprintf functions](../c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.md)\
79+
[`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)\
80+
[`scanf_s`, `_scanf_s_l`, `wscanf_s`, `_wscanf_s_l`](../c-runtime-library/reference/scanf-s-scanf-s-l-wscanf-s-wscanf-s-l.md)\
81+
[C4313](../error-messages/compiler-warnings/compiler-warning-level-1-c4313.md)\
82+
[C4477](../error-messages/compiler-warnings/C4477.md)

docs/code-quality/c6067.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
---
22
description: "Learn more about: Warning C6067"
33
title: Warning C6067
4-
ms.date: 11/04/2016
4+
ms.date: 3/02/2023
55
f1_keywords: ["C6067", "NON_STRING_ARGUMENT_TO_FORMAT_FUNCTION", "__WARNING_NON_STRING_ARGUMENT_TO_FORMAT_FUNCTION"]
66
helpviewer_keywords: ["C6067"]
7-
ms.assetid: 6fbaee53-daaa-4ba5-9b11-2a8066d86240
87
---
98
# Warning C6067
109

1110
> Parameter '*number*' in call to '*function*' must be the address of the string
1211
12+
## Remarks
13+
1314
This warning indicates a mismatch between the format specifier and the function parameter. Even though the warning suggests using the address of the string, you must check the type of parameter a function expects before correcting the problem. For example, a `%s` specification for `printf` requires a string argument, but a `%s` specification in `scanf` requires an address of the string.
1415

1516
This defect is likely to cause a crash or corruption of some form.
@@ -26,7 +27,7 @@ The following code generates this warning because an integer is passed instead o
2627
void f_defective()
2728
{
2829
char *str = "Hello, World!";
29-
printf("String:\n %s", 1); // warning
30+
printf("String:\n %s", 1);
3031
// code ...
3132
}
3233
```
@@ -98,6 +99,9 @@ void f_safe()
9899

99100
## See also
100101

101-
- [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)
102-
- [printf, \_printf\_l, wprintf, \_wprintf\_l](../c-runtime-library/reference/printf-printf-l-wprintf-wprintf-l.md)
103-
- [scanf\_s, \_scanf\_s\_l, wscanf\_s, \_wscanf\_s\_l](../c-runtime-library/reference/scanf-s-scanf-s-l-wscanf-s-wscanf-s-l.md)
102+
[Format specification syntax: printf and wprintf functions](../c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.md)\
103+
[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)\
104+
[printf, \_printf\_l, wprintf, \_wprintf\_l](../c-runtime-library/reference/printf-printf-l-wprintf-wprintf-l.md)\
105+
[scanf\_s, \_scanf\_s\_l, wscanf\_s, \_wscanf\_s\_l](../c-runtime-library/reference/scanf-s-scanf-s-l-wscanf-s-wscanf-s-l.md)\
106+
[C4313](../error-messages/compiler-warnings/compiler-warning-level-1-c4313.md)\
107+
[C4477](../error-messages/compiler-warnings/C4477.md)

docs/code-quality/c6270.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
---
22
description: "Learn more about: Warning C6270"
33
title: Warning C6270
4-
ms.date: 10/03/2022
4+
ms.date: 3/03/2023
55
f1_keywords: ["C6270", "MISSING_FLOAT_ARGUMENT_TO_FORMAT_FUNCTION", "__WARNING_MISSING_FLOAT_ARGUMENT_TO_FORMAT_FUNCTION"]
66
helpviewer_keywords: ["C6270"]
7-
ms.assetid: 34467f6e-98cf-489c-ae5e-c08a744d86c3
87
---
98
# Warning C6270
109

1110
> Missing float argument to '*function-name*': add a float argument corresponding to conversion specifier '*number*'
1211
13-
This warning indicates that not enough arguments are provided to match a format string; at least one of the missing arguments is a floating-point number.
14-
1512
## Remarks
1613

17-
This defect can lead to crashes, in addition to potentially incorrect output.
14+
This warning indicates that not enough arguments are 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.
1815

1916
Code analysis name: `MISSING_FLOAT_ARGUMENT_TO_FORMAT_FUNCTION`
2017

@@ -42,5 +39,7 @@ void f()
4239

4340
## See also
4441

42+
[Format specification syntax: printf and wprintf functions](../c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.md)\
4543
[`sprintf`, `_sprintf_l`, `swprintf`, `_swprintf_l`, `__swprintf_l`](../c-runtime-library/reference/sprintf-sprintf-l-swprintf-swprintf-l-swprintf-l.md)\
46-
[`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)
44+
[`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)\
45+
[C4473](../error-messages/compiler-warnings/C4473.md)

docs/code-quality/c6271.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
22
description: "Learn more about: Warning C6271"
33
title: Warning C6271
4-
ms.date: 11/04/2016
4+
ms.date: 3/06/2023
55
f1_keywords: ["C6271", "EXTRA_ARGUMENT_TO_FORMAT_FUNCTION", "__WARNING_EXTRA_ARGUMENT_TO_FORMAT_FUNCTION"]
66
helpviewer_keywords: ["C6271"]
7-
ms.assetid: 24703b17-5bdc-4f97-a56a-b2ea48bacc43
87
---
98
# Warning C6271
109

11-
> Extra argument passed to '*function*': parameter '*number*' is not used by the format string
10+
> Extra argument passed to '*function*'
1211
1312
## Remarks
1413

15-
This warning indicates that additional arguments are being provided beyond the ones specified by the format string. By itself, this defect won't have any visible effect although it indicates that the programmer's intent isn't reflected in the code.
14+
This warning indicates that extra arguments are being provided beyond the ones specified by the format string. By itself, this defect doesn't have any visible effect although it indicates that the programmer's intent isn't reflected in the code.
1615

1716
Code analysis name: `EXTRA_ARGUMENT_TO_FORMAT_FUNCTION`
1817

@@ -22,44 +21,44 @@ The following sample code generates this warning:
2221

2322
```cpp
2423
#include <stdio.h>
25-
#include <string.h>
2624

2725
void f()
2826
{
2927
char buff[5];
3028

31-
sprintf(buff,"%d",1,2);
29+
sprintf(buff, "%d", 1, 2);
3230
}
3331
```
3432

35-
To correct this warning, use the following sample code:
33+
To correct this warning, remove the unused parameter or modify the format string to take it into account:
3634

3735
```cpp
3836
#include <stdio.h>
39-
#include <string.h>
4037

4138
void f()
4239
{
4340
char buff[5];
4441

45-
sprintf(buff,"%d, %d",1,2);
42+
sprintf(buff, "%d, %d", 1, 2);
4643
}
4744
```
4845

4946
The following sample code calls the safe string manipulation function, `sprintf_s`, to correct this warning:
5047

5148
```cpp
5249
#include <stdio.h>
53-
#include <string.h>
5450

5551
void f()
5652
{
5753
char buff[5];
5854

59-
sprintf_s( buff, 5,"%s %d", 1,2 ); //safe version
55+
sprintf_s( buff, 5, "%d %d", 1, 2 ); //safe version
6056
}
6157
```
6258

6359
## See also
6460

65-
[sprintf, _sprintf_l, swprintf, _swprintf_l, \__swprintf_l](../c-runtime-library/reference/sprintf-sprintf-l-swprintf-swprintf-l-swprintf-l.md)
61+
[Format specification syntax: printf and wprintf functions](../c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.md)\
62+
[`sprintf`, `_sprintf_l`, `swprintf`, `_swprintf_l`, `__swprintf_l`](../c-runtime-library/reference/sprintf-sprintf-l-swprintf-swprintf-l-swprintf-l.md)\
63+
[`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)\
64+
[C4474](../error-messages/compiler-warnings/compiler-warnings-c4400-through-c4599.md)

0 commit comments

Comments
 (0)