Skip to content

qsort4.c uses memcpy illegally #4

@andrew-appel

Description

@andrew-appel

qsort4.c has a bug: it can call memcpy with overlapping source and destination arguments. This is "undefined behavior" in the C standard. Therefore the cbench-vst verification of qsort4 has one admitted lemma, for the case where we must assume that memcpy(dest,src,size) has no effect when dest=src.

Here's the code:

   if (i <= j) {
        memcpy(tmp, a(i), size);
        memcpy(a(i), a(j), size);
        memcpy(a(j), tmp, size);
        i++; j--;
      }

and indeed it is possible that i==j -- just sort a 2-element list [0;1].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions