Skip to content

memcpy() does not take pointer offset into account #1857

Closed
@david-k

Description

@david-k

Hi,
memcpy() does not seem to take pointer offsets into account, e.g. memcpy(dest + 1, src + 1, sizeof(int)) compiles to the equivalent of memcpy(dest, src, sizeof(int)).

void test()
{
    int a = 1;
    int b = 2;
    int dest[2];

    memcpy(dest, &a, sizeof(int));
    memcpy(dest + 1, &b, sizeof(int));

    assert(dest[1] == b); // Erroneously fails in CBMC 5.8, but works as expected in CBMC 5.6
}

In CBMC 5.6, memcpy() was implemented using a loop, but I think in 5.7 or 5.8 this was changed to using __CPROVER_array_copy/__CPROVER_array_replace. Could this have anything to do with the error?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions