[Bug libstdc++/105258] New: std::get_temporary_buffer() does not respect alignment (affects std::stable_sort())
wielkiegie at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Apr 13 08:37:17 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105258
Bug ID: 105258
Summary: std::get_temporary_buffer() does not respect alignment
(affects std::stable_sort())
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: wielkiegie at gmail dot com
Target Milestone: ---
Created attachment 52795
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52795&action=edit
The reproducer
The `std::get_temporary_buffer()` function uses raw `operator new()` to
allocate enough memory for the `sizeof(T) * count` bytes. However, it does not
take `alignof(T)` into account.
While `std::get_temporary_buffer()` is deprecated in C++17 [1], it is still
used internally by `std::stable_sort()`.
The issue is reproducible on the gcc HEAD [2]. Please note that the alignment
issues might not be deterministic as the allocator can return an allocation of
correct alignment by accident.
For convenience, I have also attached the reproducer to this bug report.
[1] https://en.cppreference.com/w/cpp/memory/get_temporary_buffer
[2] https://wandbox.org/permlink/zZt6Weh3V1XWmUWt
More information about the Gcc-bugs
mailing list