This is the mail archive of the
mailing list for the GCC project.
Re: C++ interop issue due to non-null pointers
- From: Florian Weimer <fweimer at redhat dot com>
- To: Trevor Saunders <tsaunders at mozilla dot com>
- Cc: Jonathan Wakely <jwakely dot gcc at gmail dot com>, GCC <gcc at gcc dot gnu dot org>
- Date: Tue, 17 Jun 2014 16:34:16 +0200
- Subject: Re: C++ interop issue due to non-null pointers
- Authentication-results: sourceware.org; auth=none
- References: <53997584 dot 8080706 at redhat dot com> <CAH6eHdRua1KTs1QXf2Pu39orxCx6agdzwdzVvcPkcNVEEkRErA at mail dot gmail dot com> <53A03782 dot 9020208 at redhat dot com> <20140617142403 dot GA25179 at tsaunders-iceball dot corp dot tor1 dot mozilla dot com>
On 06/17/2014 04:24 PM, Trevor Saunders wrote:
On Tue, Jun 17, 2014 at 02:41:38PM +0200, Florian Weimer wrote:
On 06/12/2014 12:04 PM, Jonathan Wakely wrote:
What can we do about it?
How common is it to use std::vector with qsort, rather than
std::sort(vec.begin(), vec.end()), which does the right thing?
Our very own vec::qsort has the same problem, so I'd wager that it's fairly
template<typename T, typename A>
vec<T, A, vl_embed>::qsort (int (*cmp) (const void *, const void *))
if (length () > 1)
::qsort (address (), length (), sizeof (T), cmp);
So I don't think it does.
Ah, I looked at the wrong branch. It was fixed in r206709, apparently
for performance reasons, see PR46590.
We could make vector::data() guarantee a non-null pointer with
_FORTIFY_SOURCE, but I'd rather not do so in "unfortified" code. Some
users would object to the extra check needed.
Or we could remove the nonnull attributes, so that the additional checks are
I'm not that familiar with the exact requirements of std::vector, could
we use the same trick as
that is instead of pointing at null point at a global header used for
all empty vectors?
For std::vector, we could use reinterpret_cast<T*>(alignof(T)) or
reinterpret_cast<T*>(sizeof(T)) if those are sufficiently well-defined
as far as GCC is concerned. The smaller constant is easier to load, and
no relocation is required.
Florian Weimer / Red Hat Product Security Team