void * used in a typedef, member, parameter, or variable
ID |
c.maintainability.avoid_void_pointer |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
medium |
Remediation Effort |
medium |
Resource |
Type Safety |
Language |
C / C++ |
Description
Reports void * used as the type of a typedef alias, a struct/class member, a function parameter, or a variable.
Rationale
A void * erases the pointee’s type, so the compiler can no longer catch a mismatched assignment, a wrong-type dereference after a cast, or an incorrect sizeof computed against the pointer. Every use downstream of the declaration has to be trusted to cast it back to the right type by convention alone, which is exactly the class of defect static and runtime type checking exist to catch.
The following code illustrates the pattern detected by this rule:
// FLAGGED: void * used in a typedef, member, parameter, or variable
typedef void *Handle;