Width-unspecified integer type

ID

c.portability.fixed_width_integer

Severity

low

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

medium

Resource

Portability

Language

C / C++

Description

This declares a variable with a width-unspecified integer type (short/long/long long). The size of these types differs across platforms and compilers (e.g. long is 32-bit on Windows LLP64 but 64-bit on Unix LP64), which breaks assumptions about ranges and struct layout. Prefer a fixed-width type from <stdint.h> such as int32_t, int64_t or uint64_t.

Rationale

This declares a variable with a width-unspecified integer type (short/long/long long). The size of these types differs across platforms and compilers (e.g. long is 32-bit on Windows LLP64 but 64-bit on Unix LP64), which breaks assumptions about ranges and struct layout. Prefer a fixed-width type from <stdint.h> such as int32_t, int64_t or uint64_t.

The following code illustrates the pattern detected by this rule:

void f(void)
{
    // FLAGGED: Width-unspecified integer type
    short a;
    // FLAGGED: Width-unspecified integer type
    long b;
    // FLAGGED: Width-unspecified integer type
    unsigned long c;
    // FLAGGED: Width-unspecified integer type
    long long d;
    // FLAGGED: Width-unspecified integer type
    unsigned short e;
    // FLAGGED: Width-unspecified integer type
    long g = 5;
    int good;
    int32_t better;
    uint64_t best = 0;
    (void)a; (void)b; (void)c; (void)d; (void)e; (void)g; (void)good; (void)better; (void)best;
}

Remediation

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

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved