diff --git a/libstdc++-v3/include/debug/debug.h b/libstdc++-v3/include/debug/debug.h index 1db5aa34c55..15df64f54d9 100644 --- a/libstdc++-v3/include/debug/debug.h +++ b/libstdc++-v3/include/debug/debug.h @@ -70,7 +70,11 @@ namespace __gnu_debug __UINTPTR_TYPE__ __l = (__UINTPTR_TYPE__)__last; if (const std::size_t __sz = __builtin_object_size(__first, 3)) return __f <= __l && (__l - __f) <= __sz; +#ifdef _GLIBCXX_DEBUG + return __f <= __l && static_cast(__f) == static_cast(__l); +#else return true; +#endif } #ifndef _GLIBCXX_DEBUG @@ -89,7 +93,11 @@ namespace __gnu_debug { if (const std::size_t __sz = __builtin_object_size(__first, 3)) return __n <= __sz; +#ifdef _GLIBCXX_DEBUG + return static_cast(__first) == static_cast(__n); +#else return true; +#endif } #endif } diff --git a/libstdc++-v3/include/debug/helper_functions.h b/libstdc++-v3/include/debug/helper_functions.h index c0144ced979..ed11147b451 100644 --- a/libstdc++-v3/include/debug/helper_functions.h +++ b/libstdc++-v3/include/debug/helper_functions.h @@ -266,6 +266,12 @@ namespace __gnu_debug return __valid_range_aux(__first, __last, _Integral()); } + template + __attribute__((__always_inline__)) _GLIBCXX14_CONSTEXPR + inline bool + __valid_range(_Tp* __first, _Tp* __last) _GLIBCXX_NOEXCEPT + { return __gnu_debug::__valid_range_p(__first, __last); } + template bool __valid_range(const _Safe_iterator<_Iterator, _Sequence, _Category>&, @@ -285,6 +291,12 @@ namespace __gnu_debug __can_advance(_InputIterator, _Size) { return true; } + template + __attribute__((__always_inline__)) _GLIBCXX_CONSTEXPR + inline bool + __can_advance(_Tp* __p, _Size __n) _GLIBCXX_NOEXCEPT + { return __gnu_debug::__valid_range_n(__p, (std::size_t)__n); } + template bool diff --git a/libstdc++-v3/include/debug/macros.h b/libstdc++-v3/include/debug/macros.h index 9e1288cf4d9..5c655083cb3 100644 --- a/libstdc++-v3/include/debug/macros.h +++ b/libstdc++-v3/include/debug/macros.h @@ -461,6 +461,6 @@ _GLIBCXX_DEBUG_VERIFY(_This.get_allocator() == _Other.get_allocator(), \ #define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_PEDASSERT(_String != 0) #define __glibcxx_check_string_len(_String,_Len) \ - _GLIBCXX_DEBUG_PEDASSERT(_String != 0 || _Len == 0) + _GLIBCXX_DEBUG_ASSERT(__gnu_debug::__valid_range_n(_String, _Len)) #endif diff --git a/libstdc++-v3/include/debug/stl_iterator.h b/libstdc++-v3/include/debug/stl_iterator.h index edeb42ebe98..65c1828d6e4 100644 --- a/libstdc++-v3/include/debug/stl_iterator.h +++ b/libstdc++-v3/include/debug/stl_iterator.h @@ -29,6 +29,7 @@ #ifndef _GLIBCXX_DEBUG_STL_ITERATOR_H #define _GLIBCXX_DEBUG_STL_ITERATOR_H 1 +#include #include namespace __gnu_debug diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc index 0128535135e..59382defe27 100644 --- a/libstdc++-v3/src/c++11/debug.cc +++ b/libstdc++-v3/src/c++11/debug.cc @@ -25,6 +25,7 @@ #include #include +#include #include #include #include