Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions docs/code-quality/c33001.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ helpviewer_keywords: ["C33001"]

## Remarks

This warning is triggered when an uninitialized `VARIANT` is passed to an API such as `VariantClear`
that expects an initialized `VARIANT`.
This warning is triggered when an uninitialized `VARIANT` is passed to an API, such as `VariantClear`, that clears the object. Initialize the `VARIANT` before passing it to these functions so it can be properly cleared.

This warning applies to these functions:

* `VariantClear`
* `PropVariantClear`
* `VariantCopy`
* `VariantCopyInd`
* `VariantChangeType`
* `VariantChangeTypeEx`
* `DestroyPropVariant`

Code analysis name: `VARIANTCLEAR_UNINITIALIZED`

## Example

The following sample code causes warning C33001:
The following code causes warning C33001:

```cpp
#include <Windows.h>
Expand All @@ -36,11 +45,11 @@ HRESULT foo(bool some_condition)
//...
}

VariantClear(&var); // C33001
VariantClear(&var); // C33001
}
```

These warnings are corrected by ensuring `VariantClear` is called only for a properly initialized `VARIANT`:
In this example, the warning is corrected by calling `VariantClear` only after `var` has been initialized:

```cpp
#include <Windows.h>
Expand All @@ -54,12 +63,12 @@ HRESULT foo(bool some_condition)
//...
VariantInit(&var);
//...
VariantClear(&var); // C33001
VariantClear(&var); // OK
}
}
```

## See also

[C33004](./c33004.md)
[C33004](./c33004.md)\
[C33005](./c33005.md)