This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PR 57779 New debug check


On 07/11/2013 06:58 PM, Jonathan Wakely wrote:
On 11 July 2013 17:43, Paolo Carlini wrote:
+      if (&(*(__it._M_get_sequence()->_M_base().end()))

Isn't this a dereference of a non-dereferenceable iterator?
Looks like this function does a very tricky work! I think that at least we
should use __addressof and std::less, std::greater, etc to compare pointers.
In general, we should probably try to be conservative in the first
implementation of the check, act only when we *really* know we have
contiguous memory, not even "blocks", like for std::deque.
The safest way would probably be to add an __is_contiguous trait,
specialized for the __gnu_debug versions of vector, array, and
dynarray, then check __is_contiguous<_Sequence>.

IMO the current check is enough. Of course it will consider a std::deque with only 1 block as continuous memory, and so what ? Passing a pointer to those continuous elements is bad and will be detected then. As soon as std::deque elements will be split in at least 2 blocks the check won't be performed anymore but it doesn't make the check useless. It would be worst if the check was generating false positive results.

I am indeed dereferencing the end iterator but as long as it is just to get the address of the resulting element it is fine. However that's a good remark cause I never realized that getting the address of this invalid iterator is in fact giving a correct result. But the Standard is saying that we shall assert in debug mode so it is fine.

François


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]