[PATCH v1 0/1] Set _M_string_length before calling _M_dispose()

Kefu Chai tchaikov@gmail.com
Mon May 1 07:06:21 GMT 2023


This patch fixes the false alarm when performing the check introduced by
bf78b43873b0b7e8f9a430df38749b8b61f9c9b8 . A minimal reproducer can be
found at https://godbolt.org/z/7q4nG68xn

I am pasting the reproducer here just in case:

#include <cstring>
#include <string>
#include <sstream>

int main() {
    unsigned char buf[sizeof(std::string)] ;
    std::memset(buf, 0xff, sizeof(buf));
    const char s[] = "1234567890abcdefg";
    std::istringstream in{s};
    std::istreambuf_iterator<char> it{in}, end;
    auto* p = new (buf) std::string(it, end);
    return 0;
}

Tested on x86_64-pc-linux-gnu, with "make check-target-libstdc++-v3".
Would be great if this change can be included in thunk, 13.2 and 12
branches.

Kefu Chai (1):
  libstdc++: Set _M_string_length before calling _M_dispose()

 libstdc++-v3/include/bits/basic_string.tcc | 1 +
 1 file changed, 1 insertion(+)

-- 
2.40.1



More information about the Libstdc++ mailing list