Skip to content

CBMC fails when empty string is passed by reference #234

Closed

Description

@avanhatt

CBMC fails with [precondition_instance.3] memcpy destination region writeable: FAILURE on this:

fn take_str(s: &str)) {
}

fn main() {
    take_str(&"".to_string());
}

The issue is that Rust seems to use a special 0x1 pointer for the empty, length-zero string. C expects memcpy to take valid pointers even when the length of the copy is zero. So, to match LLVM semantics, we should only codegen a memcpy when the length is nonzero.

Activity

  1. added
    [C] Bug
    on Jun 18, 2021
  2. self-assigned this
    on Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[C] Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions