Skip to content

Commit 1391d78

Browse files
authored
Merge pull request #4487 from MugBergerFries/patch-9
Updated C6333, C6334, C28112, C28208
2 parents 8416aad + 0519605 commit 1391d78

File tree

4 files changed

+133
-101
lines changed

4 files changed

+133
-101
lines changed

docs/code-quality/c28112.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
11
---
22
description: "Learn more about: C28112"
33
title: C28112
4-
ms.date: 11/04/2016
4+
ms.date: 08/25/2022
55
ms.topic: reference
6-
f1_keywords: ["C28112"]
6+
f1_keywords: ["C28112", "INTERLOCKED_ACCESS", "__WARNING_INTERLOCKED_ACCESS"]
77
helpviewer_keywords: ["C28112"]
88
ms.assetid: 2720a5dc-84e9-4f78-a8c7-a320c9f9216b
99
---
10-
# C28112
10+
# Warning C28112
1111

12-
> warning C28112: A variable which is accessed via an Interlocked function must always be accessed via an Interlocked function
12+
> A variable (*parameter-name*) which is accessed via an Interlocked function must always be accessed via an Interlocked function. See line *line-number*: It is not always safe to access a variable which is accessed via the Interlocked\* family of functions in any other way.
1313
14-
See line *[number]*: It is not always safe to access a variable which is accessed via the Interlocked\* family of functions in any other way.
14+
A variable that is accessed by using the Interlocked executive support routines, such as InterlockedCompareExchangeAcquire, is later accessed by using a different function.
1515

16-
A variable that is accessed by using the Interlocked executive support routines, such as InterlockedCompareExchangeAcquire, is later accessed by using a different function. Although certain ordinary assignments, accesses, and comparisons to variables that are used by the Interlocked\* routines can be safely accessed by using a different function, the risk is great enough to justify examining each instance.
16+
## Remarks
17+
18+
`InterlockedXxx` functions are intended to provide atomic operations, but are only atomic with respect to other `InterlockedXxx` functions. Although certain ordinary assignments, accesses, and comparisons to variables that are used by the Interlocked\* routines can be safely accessed by using a different function, the risk is great enough to justify examining each instance.
19+
20+
Code analysis name: INTERLOCKED_ACCESS
1721

1822
## Example
1923

20-
The following code example generates this warning:
24+
The following code generates this warning:
2125

2226
```cpp
23-
inter_var --;
24-
...
27+
inter_var--;
28+
//code
2529
InterlockedIncrement(&inter_var);
2630
```
2731
28-
The following code example avoids this warning:
32+
The following code corrects this warning by strictly accessing `inter_var` through `InterlockedXxx` functions:
2933
3034
```cpp
3135
InterlockedDecrement(&inter_var);
32-
...
36+
//code
3337
InterlockedIncrement(&inter_var);
3438
```
39+
40+
## See Also
41+
42+
[InterlockedIncrement function (wdm.h)](/windows-hardware/drivers/ddi/wdm/nf-wdm-interlockedincrement)
43+
[InterlockedDecrement function (wdm.h)](/windows-hardware/drivers/ddi/wdm/nf-wdm-interlockeddecrement)

docs/code-quality/c28208.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
11
---
22
description: "Learn more about: C28208"
33
title: C28208
4-
ms.date: 11/04/2016
4+
ms.date: 08/30/2022
55
ms.topic: reference
6-
f1_keywords: ["C28208"]
6+
f1_keywords: ["C28208", "FUNCTION_TYPE_REDECLARATION", "__WARNING_FUNCTION_TYPE_REDECLARATION"]
77
helpviewer_keywords: ["C28208"]
88
ms.assetid: e9a8ce37-3b05-4202-b078-5570ae496d1d
99
---
10-
# C28208
10+
# Warning C28208
1111

12-
> warning C28208: Function \<function> was previously defined with a different parameter list at \<file>(\<line>). Some analysis tools will yield incorrect results
12+
> Function *function_name* was previously defined with a different parameter list at *file_name*(*line_number*). Some analysis tools will yield incorrect results
1313
14-
This warning is reported when a function's known definition doesn't match another occurrence.
14+
## Remarks
15+
16+
This warning will almost always accompany [Compiler Warning (level 1) C4028](/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4028). Both warn of a mismatch between the parameters of a function's declaration and its definition. However, this specific error indicates a more niche case than C4028. C28208 indicates not only that a mismatch exists, but that it also can cause issues with analysis tools. This warning most notably occurs when the mismatch exists between a `typedef` function pointer and the definition of that function. This warning is demonstrated in the example below.
17+
18+
Code analysis name: FUNCTION_TYPE_REDECLARATION
19+
20+
## Example
21+
22+
The following code will generate C28208. `test_type` takes in a void pointer in its declaration, but `my_test1` takes in an integer pointer instead. `my_test2` remediates this issue by making sure the definition parameter match the declaration parameters.
23+
24+
*From example.h:*
25+
26+
```cpp
27+
typedef void test_type(void*);
28+
```
29+
30+
*From example.cpp:*
31+
32+
```cpp
33+
test_type my_test1;
34+
test_type my_test2;
35+
void my_test1(int* x){}; // Will generate C28208
36+
void my_test2(void* x){}; // Will not generate C28208
37+
38+
int main()
39+
{
40+
// Code
41+
}
42+
```

docs/code-quality/c6333.md

Lines changed: 63 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
---
22
description: "Learn more about: C6333"
33
title: C6333
4-
ms.date: 11/04/2016
4+
ms.date: 08/25/2022
55
ms.topic: reference
6-
f1_keywords: ["C6333"]
6+
f1_keywords: ["C6333", "VIRTUALFREEINVALIDPARAM3", "__WARNING_VIRTUALFREEINVALIDPARAM3"]
77
helpviewer_keywords: ["C6333"]
88
ms.assetid: 4b8fa4b2-a3a0-4d00-bec7-76686b66fcf9
99
---
10-
# C6333
10+
# Warning C6333
1111

12-
> warning C6333: Invalid parameter: passing MEM_RELEASE and a non-zero dwSize parameter to \<function> is not allowed. This results in the failure of this call
12+
> Invalid parameter: passing MEM_RELEASE and a non-zero dwSize parameter to '*function_name*' is not allowed. This results in the failure of this call
1313
14-
This warning indicates an invalid parameter is being passed to VirtualFree or VirtualFreeEx. Both of these functions reject a dwFreeType of MEM_RELEASE with a non-zero value of dwSize. When passing MEM_RELEASE, the dwSize parameter must be zero. Also, make sure that the return value of this function is not ignored.
14+
## Remarks
15+
16+
Both `VirtualFree` and `VirtualFreeEx` reject a `dwFreeType` of `MEM_RELEASE` with a non-zero value of `dwSize`. When `MEM_RELEASE` is passed, the `dwSize` parameter must be zero.
17+
18+
Code analysis name: VIRTUALFREEINVALIDPARAM3
1519

1620
## Example
1721

18-
The following sample code generates this warning:
22+
The following code sample generates this warning:
1923

2024
```cpp
2125
#include <windows.h>
@@ -24,36 +28,36 @@ The following sample code generates this warning:
2428
DWORD dwPages = 0; // count of pages
2529
DWORD dwPageSize; // page size
2630

27-
VOID f( VOID )
31+
VOID f(VOID)
2832
{
29-
LPVOID lpvBase; // base address of the test memory
30-
BOOL bSuccess;
31-
SYSTEM_INFO sSysInfo; // system information
32-
33-
GetSystemInfo( &sSysInfo );
34-
dwPageSize = sSysInfo.dwPageSize;
35-
36-
// Reserve pages in the process's virtual address space
37-
lpvBase = VirtualAlloc(
38-
NULL, // system selects address
39-
PAGELIMIT*dwPageSize,// size of allocation
40-
MEM_RESERVE,
41-
PAGE_NOACCESS );
42-
if (lpvBase)
43-
{
44-
// code to access memory
45-
}
46-
else
47-
{
48-
return;
49-
}
50-
51-
bSuccess = VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_RELEASE);
52-
//code...
33+
LPVOID lpvBase; // base address of the test memory
34+
BOOL bSuccess;
35+
SYSTEM_INFO sSysInfo; // system information
36+
37+
GetSystemInfo(&sSysInfo);
38+
dwPageSize = sSysInfo.dwPageSize;
39+
40+
// Reserve pages in the process's virtual address space
41+
lpvBase = VirtualAlloc(
42+
NULL, // system selects address
43+
PAGELIMIT*dwPageSize,// size of allocation
44+
MEM_RESERVE,
45+
PAGE_NOACCESS);
46+
if (lpvBase)
47+
{
48+
// code to access memory
49+
}
50+
else
51+
{
52+
return;
53+
}
54+
55+
bSuccess = VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_RELEASE);
56+
//code...
5357
}
5458
```
5559
56-
To correct this warning, use the following sample code:
60+
To correct this warning, ensure that the value of `dwSize` is 0 in the call to `VirtualFree`:
5761
5862
```cpp
5963
#include <windows.h>
@@ -62,37 +66,37 @@ To correct this warning, use the following sample code:
6266
DWORD dwPages = 0; // count of pages
6367
DWORD dwPageSize; // page size
6468
65-
VOID f( VOID )
69+
VOID f(VOID)
6670
{
67-
LPVOID lpvBase; // base address of the test memory
68-
BOOL bSuccess;
69-
SYSTEM_INFO sSysInfo; // system information
70-
71-
GetSystemInfo( &sSysInfo );
72-
dwPageSize = sSysInfo.dwPageSize;
73-
74-
// Reserve pages in the process's virtual address space
75-
lpvBase = VirtualAlloc(
76-
NULL, // system selects address
77-
PAGELIMIT*dwPageSize,// size of allocation
78-
MEM_RESERVE,
79-
PAGE_NOACCESS );
80-
if (lpvBase)
81-
{
82-
// code to access memory
83-
}
84-
else
85-
{
86-
return;
87-
}
88-
bSuccess = VirtualFree(lpvBase, 0, MEM_RELEASE );
89-
90-
// VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_DECOMMIT);
91-
// code...
71+
LPVOID lpvBase; // base address of the test memory
72+
BOOL bSuccess;
73+
SYSTEM_INFO sSysInfo; // system information
74+
75+
GetSystemInfo(&sSysInfo);
76+
dwPageSize = sSysInfo.dwPageSize;
77+
78+
// Reserve pages in the process's virtual address space
79+
lpvBase = VirtualAlloc(
80+
NULL, // system selects address
81+
PAGELIMIT*dwPageSize, // size of allocation
82+
MEM_RESERVE,
83+
PAGE_NOACCESS);
84+
if (lpvBase)
85+
{
86+
// code to access memory
87+
}
88+
else
89+
{
90+
return;
91+
}
92+
bSuccess = VirtualFree(lpvBase, 0, MEM_RELEASE);
93+
94+
// VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_DECOMMIT);
95+
// code...
9296
}
9397
```
9498

95-
You can also use VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_DECOMMIT); call to decommit pages, and later release them using MEM_RELEASE flag.
99+
You can also use `VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_DECOMMIT);` call to decommit pages, and later release them using `MEM_RELEASE` flag.
96100

97101
## See also
98102

docs/code-quality/c6334.md

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,45 @@
11
---
22
description: "Learn more about: C6334"
33
title: C6334
4-
ms.date: 11/04/2016
4+
ms.date: 08/25/2022
55
ms.topic: reference
6-
f1_keywords: ["C6334"]
6+
f1_keywords: ["C6334", "SIZEOFEXPR", "__WARNING_SIZEOFEXPR"]
77
helpviewer_keywords: ["C6334"]
88
ms.assetid: 83c8abfb-b11e-4573-8c6f-95b205d32137
99
---
10-
# C6334
10+
# Warning C6334
1111

12-
> warning C6334: sizeof operator applied to an expression with an operator may yield unexpected results
12+
> sizeof operator applied to an expression with an operator may yield unexpected results
1313
14-
This warning indicates a misuse of the **`sizeof`** operator. The **`sizeof`** operator, when applied to an expression, yields the size of the type of the resulting expression.
14+
## Remarks
1515

16-
For example, in the following code:
16+
The `sizeof` operator, when applied to an expression, yields the size of the type of the resulting expression.
1717

18-
```cpp
19-
char a[10];
20-
size_t x;
21-
22-
x = sizeof (a - 1);
23-
```
24-
25-
`x` will be assigned the value 4, not 9, because the resulting expression is no longer a pointer to the array `a`, but simply a pointer.
18+
Code analysis name: SIZEOFEXPR
2619

2720
## Example
2821

29-
The following code generates this warning:
22+
The following code generates this warning. Since `a - 4` is an expression, `sizeof` will return the size of the resulting pointer, not the size of the structure found at that pointer:
3023

3124
```cpp
3225
void f( )
3326
{
34-
size_t x;
35-
char a[10];
36-
37-
x= sizeof (a - 4);
38-
// code...
27+
size_t x;
28+
char a[100];
29+
x = sizeof(a - 4);
30+
assert(x == 96); //assert fails since x == sizeof(char*)
3931
}
4032
```
4133
42-
To correct this warning, use the following code:
34+
To correct this warning, ensure that you're working with the return value of `sizeof`, not the argument to it:
4335
4436
```cpp
4537
void f( )
4638
{
47-
size_t x;
48-
char a[10];
49-
50-
x= sizeof (a) - 4;
51-
// code...
39+
size_t x;
40+
char a[100];
41+
x = sizeof(a) - 4;
42+
assert(x == 96); //assert succeeds
5243
}
5344
```
5445

0 commit comments

Comments
 (0)