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
> 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.
13
13
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.
15
15
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
17
21
18
22
## Example
19
23
20
-
The following code example generates this warning:
24
+
The following code generates this warning:
21
25
22
26
```cpp
23
-
inter_var--;
24
-
...
27
+
inter_var--;
28
+
//code
25
29
InterlockedIncrement(&inter_var);
26
30
```
27
31
28
-
The following code example avoids this warning:
32
+
The following code corrects this warning by strictly accessing `inter_var` through `InterlockedXxx` functions:
29
33
30
34
```cpp
31
35
InterlockedDecrement(&inter_var);
32
-
...
36
+
//code
33
37
InterlockedIncrement(&inter_var);
34
38
```
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)
> 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
13
13
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
+
typedefvoidtest_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
> 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
13
13
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
15
19
16
20
## Example
17
21
18
-
The following sample code generates this warning:
22
+
The following code sample generates this warning:
19
23
20
24
```cpp
21
25
#include<windows.h>
@@ -24,36 +28,36 @@ The following sample code generates this warning:
24
28
DWORD dwPages = 0; // count of pages
25
29
DWORD dwPageSize; // page size
26
30
27
-
VOID f(VOID)
31
+
VOID f(VOID)
28
32
{
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
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.
> 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
13
13
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
15
15
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.
17
17
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
26
19
27
20
## Example
28
21
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:
30
23
31
24
```cpp
32
25
voidf( )
33
26
{
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*)
39
31
}
40
32
```
41
33
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:
0 commit comments