https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78448

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Wed Aug 22 22:22:40 2018
New Revision: 263789

URL: https://gcc.gnu.org/viewcvs?rev=263789&root=gcc&view=rev
Log:
PR libstdc++/78448 limit vector::max_size and deque::max_size

The container requirements imply that max_size() can't exceed the
maximum value of the container's difference_type. Enforce this for
std::vector and std::deque, and add checks to ensure the container
doesn't grow larger than that.

        PR libstdc++/78448
        * include/bits/deque.tcc (deque::_M_range_initialize): Use
        _S_check_init_len to check size.
        (deque::_M_push_back_aux, deque::_M_push_front_aux): Throw length
        error if size would exceed max_size().
        * include/bits/stl_deque.h (_Deque_base::size_type): Remove typedef.
        (_Deque_base(_Deque_base&&, const allocator_type&, size_t)): Use
        size_t instead of size_type.
        (deq(size_type, const allocator_type&)
        (deq(size_type, const value_type&, const allocator_type&)
        (deque::_M_initialize_dispatch): Use _S_check_init_len to check size.
        (deque::max_size): Call _S_max_size.
        (deque::_S_check_init_len, deque::_S_max_size): New functions.
        * include/bits/stl_vector.h (vector(size_type, const allocator_type&))
        (vector(size_type, const value_type&, const allocator_type&))
        (vector::_M_initialize_dispatch, vector::_M_range_initialize): Use
        _S_check_init_len to check size.
        (vector::max_size): Call _S_max_size.
        (vector::_M_check_len): Prevent max from being expanded as a
        function-like macro.
        (vector::_S_check_init_len, vector::_S_max_size): New functions.
        * include/bits/vector.tcc (vector::_M_assign_aux): Use
        _S_check_init_len to check size.
        * testsuite/23_containers/deque/capacity/max_size.cc: New test.
        * testsuite/23_containers/vector/capacity/max_size.cc: New test.

Added:
    trunk/libstdc++-v3/testsuite/23_containers/deque/capacity/max_size.cc
    trunk/libstdc++-v3/testsuite/23_containers/vector/capacity/max_size.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/deque.tcc
    trunk/libstdc++-v3/include/bits/stl_deque.h
    trunk/libstdc++-v3/include/bits/stl_vector.h
    trunk/libstdc++-v3/include/bits/vector.tcc

Reply via email to