[Development] QtCore missing check for memory allocation
Thiago Macieira
thiago.macieira at intel.com
Wed Feb 25 16:21:41 CET 2015
On Wednesday 25 February 2015 13:35:17 Ulf Hermann wrote:
> We should thus do Q_CHECK_PTR on every memory allocation in Qt and we should
> fix Q_CHECK_PTR so that it works under all circumstances.
I disagree on both accounts.
> > Is QT_NO_DEBUG really disabling the check for valid memory allocation?
>
> You need QT_NO_EXCEPTIONS and QT_NO_DEBUG for Q_CHECK_PTR to be a qt_noop().
> I can't say I like this situation, but the point seems to be that you
> cannot throw bad_alloc if you've compiled without exceptions. I would argue
> for just crashing in this case, by accessing a known-bad address. That's
> quite a behavior change, of course.
That's undefined behaviour. If you write code:
if (!p)
*(char*)p = 42; // crash
The compiler will simply eliminate your code because it *knows* that you never
dereference null pointers.
The only thing you can reliably do is raise(SIGSEGV).
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Development
mailing list