Use of reinterpret_cast

ID

c.maintainability.reinterpret_cast

Severity

low

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

medium

Resource

Type Safety

Language

C / C++

Description

reinterpret_cast reinterprets the bit pattern of a value as an unrelated type, bypassing the type system and often producing implementation-defined or undefined behavior. Prefer a safe alternative (static_cast, std::bit_cast, a proper conversion) or redesign to avoid the cast.

Rationale

reinterpret_cast reinterprets the bit pattern of a value as an unrelated type, bypassing the type system and often producing implementation-defined or undefined behavior. Prefer a safe alternative (static_cast, std::bit_cast, a proper conversion) or redesign to avoid the cast.

The following code illustrates the pattern detected by this rule:

void f() {
  // FLAGGED: Use of reinterpret_cast
  j = reinterpret_cast<void *>(i);
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.