This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [patch] libstdc++/65352 fix ubsan errors in std::array<T, 0>
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Thu, 28 May 2015 15:46:44 +0100
- Subject: Re: [patch] libstdc++/65352 fix ubsan errors in std::array<T, 0>
- Authentication-results: sourceware.org; auth=none
- References: <20150528115330 dot GL2985 at redhat dot com>
On 28/05/15 12:53 +0100, Jonathan Wakely wrote:
Unsurprisingly ubsan doesn't like referencing a null pointer.
With this change __array_traits::_S_ref is only used to access an
element, which is invalid for std::array<T, 0> anyway.
Tested powerpc64le-linux, committed to trunk.
I forgot the debug and profile modes, fixed like so.
1) Why do we even have _profile::array? What's it for?
2) If we could run 'make check-sanitize' I could have added tests for
this bug, and could have found it still failed in debug and profile
modes. We need to be able to run the testsuite with ubsan.
I'll commit it to trunk and gcc-5-branch after testing.
commit 7a673c403d77fb2c57620f5e4f027b679bf69635
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu May 28 15:35:43 2015 +0100
PR libstdc++/65352
* include/profile/array (array::data): Use _S_ptr.
* include/debug/array (array::data): Likewise.
diff --git a/libstdc++-v3/include/debug/array b/libstdc++-v3/include/debug/array
index 31d146e..411e816 100644
--- a/libstdc++-v3/include/debug/array
+++ b/libstdc++-v3/include/debug/array
@@ -216,11 +216,11 @@ namespace __debug
pointer
data() noexcept
- { return std::__addressof(_AT_Type::_S_ref(_M_elems, 0)); }
+ { return _AT_Type::_S_ptr(_M_elems); }
const_pointer
data() const noexcept
- { return std::__addressof(_AT_Type::_S_ref(_M_elems, 0)); }
+ { return _AT_Type::_S_ptr(_M_elems); }
};
// Array comparisons.
diff --git a/libstdc++-v3/include/profile/array b/libstdc++-v3/include/profile/array
index a90e396..5198bb3 100644
--- a/libstdc++-v3/include/profile/array
+++ b/libstdc++-v3/include/profile/array
@@ -178,11 +178,11 @@ namespace __profile
pointer
data() noexcept
- { return std::__addressof(_AT_Type::_S_ref(_M_elems, 0)); }
+ { return _AT_Type::_S_ptr(_M_elems); }
const_pointer
data() const noexcept
- { return std::__addressof(_AT_Type::_S_ref(_M_elems, 0)); }
+ { return _AT_Type::_S_ptr(_M_elems); }
};
// Array comparisons.