Skip to content

UB in std::vector<bool> constructors (read of uninitialized memory) #165867

@nunoplopes

Description

@nunoplopes

Some std::vector<bool> constructors read uninitialized memory.
They call __vallocate, which calls new, but doesn't zero the allocated buffer. Constructors then use std::fill_n and std::copy, which in turns sets bit by bit. Since storing a bit involving reading the byte first, this operations ends up reading uninitialized memory.

This simple example clearly shows the loads directly from the new operator: https://gcc.godbolt.org/z/vKaPnfT5M

cross ref (libstdc++ has the same bug): https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122506

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions