Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBMC does not recognize pointer initializations outside functions #8593

Open
AmPaschal opened this issue Feb 16, 2025 · 0 comments
Open

CBMC does not recognize pointer initializations outside functions #8593

AmPaschal opened this issue Feb 16, 2025 · 0 comments

Comments

@AmPaschal
Copy link

AmPaschal commented Feb 16, 2025

We observed that CBMC does not recognize pointers that are initialized within a C file but outside a function.
It marks these pointers as INVALID-X where X is an integer.

For example, in the code below

#define PACKETBUF_SIZE 128

static uint32_t packetbuf_aligned[(PACKETBUF_SIZE + 3) / 4];
// Initializing a pointer outside a function causes CBMC to misbehave
uint8_t *packetbuf = (uint8_t *)packetbuf_aligned;

void harness() {

    uint16_t channelId;
    uint8_t *data = packetbuf;

    memcpy(&channelId, data, 2);
    
}

packetbuf is initialized to point to the statically allocated packetbuf_aligned array.
However, when data is defined to point to packetbuf, CBMC sees the packetbuf pointer as invalid and subsequently, makes data invalid.
As a result, an error is reported in the memcpy line where data is accessed.

We tested this with CBMC v6.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant