This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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: C++ interop issue due to non-null pointers


On 06/17/2014 04:39 PM, Jakub Jelinek wrote:
On Tue, Jun 17, 2014 at 04:34:16PM +0200, Florian Weimer wrote:
I'm not that familiar with the exact requirements of std::vector, could
we use the same trick as
http://mxr.mozilla.org/mozilla-central/source/xpcom/glue/nsTArray.h#275
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.

If there is no object at those addresses, that is still undefined behavior.

GCC is the implementation, so it could be made defined there.

GCC will likely not optimize it away at this point, but having code with
undefined behavior is just asking for future trouble.  Just use "" instead?

It's always const and may lack sufficient alignment. The former isn't a problem in C++ (I think), but the alignment is an issue.

--
Florian Weimer / Red Hat Product Security Team


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