Skip to content

Undefined behavior with Vec::set_len #111

@stoneeric

Description

@stoneeric

Hello,

There are several instances within zstd-rs where Vec::set_len are used:

buffer.set_len(buffer_len);

buffer.set_len(capacity);

self.buffer.set_len(capacity);

result.set_len(max_size);

Documentation for set_len safety states:

Safety
new_len must be less than or equal to capacity().
The elements at old_len..new_len must be initialized.

The second condition is not met in the instances linked above.

It would also be great if there were more documentation about safety invariants - the samples in the documentation above include examples. That would help establish confidence in the set_len calls following the FFI calls.

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