sizeof applied to the result of another sizeof
ID |
c.correctness.sizeof_sizeof |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Suspicious Construct |
Language |
C / C++ |
Description
This applies sizeof to the result of another sizeof. sizeof always yields a size_t, so the outer call measures the size of size_t itself — a constant, almost certainly not what was intended. This is usually a stray sizeof left behind while editing, or a misplaced parenthesis. Remove the outer sizeof and keep the inner one.
Rationale
This applies sizeof to the result of another sizeof. sizeof always yields a size_t, so the outer call measures the size of size_t itself — a constant, almost certainly not what was intended. This is usually a stray sizeof left behind while editing, or a misplaced parenthesis. Remove the outer sizeof and keep the inner one.
The following code illustrates the pattern detected by this rule:
void nested_call(int x)
{
// FLAGGED: sizeof applied to the result of another sizeof
size_t s = sizeof(sizeof(x));
(void)s;
}