get rid of q_check_ptr()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2020-11-18 01:41:47 +02:00
parent 3a7005f518
commit 07675ce888
12 changed files with 37 additions and 32 deletions

View file

@ -1125,15 +1125,6 @@ bool qSharedBuild()
\sa qWarning(), {Debugging Techniques} \sa qWarning(), {Debugging Techniques}
*/ */
/*!
\fn T *q_check_ptr(T *pointer)
\relates <QtGlobal>
Users Q_CHECK_PTR on \a pointer, then returns \a pointer.
This can be used as an inline version of Q_CHECK_PTR.
*/
/*! /*!
\macro const char* Q_FUNC_INFO() \macro const char* Q_FUNC_INFO()
\relates <QtGlobal> \relates <QtGlobal>

View file

@ -554,9 +554,6 @@ Q_CORE_EXPORT void qBadAlloc();
# define Q_CHECK_PTR(p) do { if (!(p)) qBadAlloc(); } while (0) # define Q_CHECK_PTR(p) do { if (!(p)) qBadAlloc(); } while (0)
#endif #endif
template <typename T>
inline T *q_check_ptr(T *p) { Q_CHECK_PTR(p); return p; }
enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg }; enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg };
Q_CORE_EXPORT void qt_message_output(QtMsgType, const char *buf); Q_CORE_EXPORT void qt_message_output(QtMsgType, const char *buf);

View file

@ -1366,7 +1366,8 @@ void QRegExpMatchState::prepareForMatch(QRegExpEngine *eng)
#endif #endif
int numCaptures = eng->captureCount(); int numCaptures = eng->captureCount();
int newCapturedSize = 2 + 2 * numCaptures; int newCapturedSize = 2 + 2 * numCaptures;
bigArray = q_check_ptr((int *)realloc(bigArray, ((3 + 4 * ncap) * ns + 4 * ncap + newSlideTabSize + newCapturedSize)*sizeof(int))); bigArray = (int *)::realloc(bigArray, ((3 + 4 * ncap) * ns + 4 * ncap + newSlideTabSize + newCapturedSize)*sizeof(int));
Q_CHECK_PTR(bigArray);
// set all internal variables only _after_ bigArray is realloc'ed // set all internal variables only _after_ bigArray is realloc'ed
// to prevent a broken regexp in oom case // to prevent a broken regexp in oom case

View file

@ -1134,8 +1134,8 @@ void QDeclarativeData::setBindingBit(QObject *obj, int bit)
int arraySize = (props + 31) / 32; int arraySize = (props + 31) / 32;
int oldArraySize = bindingBitsSize / 32; int oldArraySize = bindingBitsSize / 32;
bindingBits = (quint32 *)q_check_ptr(realloc(bindingBits, bindingBits = (quint32 *)::realloc(bindingBits, arraySize * sizeof(quint32));
arraySize * sizeof(quint32))); Q_CHECK_PTR(bindingBits);
memset(bindingBits + oldArraySize, memset(bindingBits + oldArraySize,
0x00, 0x00,

View file

@ -81,7 +81,8 @@ public:
void insert(int idx, const T &v) { void insert(int idx, const T &v) {
if (m_count == m_capacity) { if (m_count == m_capacity) {
m_capacity += Increment; m_capacity += Increment;
m_data = (T *)q_check_ptr(realloc(m_data, m_capacity * sizeof(T))); m_data = (T *)::realloc(m_data, m_capacity * sizeof(T));
Q_CHECK_PTR(m_data);
} }
int moveCount = m_count - idx; int moveCount = m_count - idx;
if (moveCount) if (moveCount)
@ -93,7 +94,8 @@ public:
void reserve(int count) { void reserve(int count) {
if (count >= m_capacity) { if (count >= m_capacity) {
m_capacity = (count + (Increment-1)) & (0xFFFFFFFF - Increment + 1); m_capacity = (count + (Increment-1)) & (0xFFFFFFFF - Increment + 1);
m_data = (T *)q_check_ptr(realloc(m_data, m_capacity * sizeof(T))); m_data = (T *)::realloc(m_data, m_capacity * sizeof(T));
Q_CHECK_PTR(m_data);
} }
} }

View file

@ -182,7 +182,8 @@ void QDesktopWidgetPrivate::init()
if (screens) { if (screens) {
// leaks QWidget* pointers on purpose, can't delete them as pointer escapes // leaks QWidget* pointers on purpose, can't delete them as pointer escapes
screens = q_check_ptr((QWidget**) realloc(screens, j * sizeof(QWidget*))); screens = (QWidget**)::realloc(screens, j * sizeof(QWidget*));
Q_CHECK_PTR(screens);
if (j > screenCount) if (j > screenCount)
memset(&screens[screenCount], 0, (j-screenCount) * sizeof(QWidget*)); memset(&screens[screenCount], 0, (j-screenCount) * sizeof(QWidget*));
} }

View file

@ -2908,7 +2908,8 @@ void QClipData::initialize()
{ // resize { // resize
const int maxSpans = (ymax - ymin) * numRects; const int maxSpans = (ymax - ymin) * numRects;
if (maxSpans > allocated) { if (maxSpans > allocated) {
m_spans = q_check_ptr((QSpan *)realloc(m_spans, maxSpans * sizeof(QSpan))); m_spans = (QSpan *)::realloc(m_spans, maxSpans * sizeof(QSpan));
Q_CHECK_PTR(m_spans);
allocated = maxSpans; allocated = maxSpans;
} }
} }
@ -3244,7 +3245,8 @@ static void qt_span_clip(int count, const QSpan *spans, void *userData)
&newspans, newClip->allocated - newClip->count); &newspans, newClip->allocated - newClip->count);
newClip->count = newspans - newClip->m_spans; newClip->count = newspans - newClip->m_spans;
if (spans < end) { if (spans < end) {
newClip->m_spans = q_check_ptr((QSpan *)realloc(newClip->m_spans, newClip->allocated*2*sizeof(QSpan))); newClip->m_spans = (QSpan *)::realloc(newClip->m_spans, newClip->allocated*2*sizeof(QSpan));
Q_CHECK_PTR(newClip->m_spans);
newClip->allocated *= 2; newClip->allocated *= 2;
} }
} }

View file

@ -212,7 +212,8 @@ void QXRenderTessellator::addTrap(const Trapezoid &trap)
{ {
if (size == allocated) { if (size == allocated) {
allocated = qMax(2*allocated, 64); allocated = qMax(2*allocated, 64);
traps = q_check_ptr((XTrapezoid *)realloc(traps, allocated * sizeof(XTrapezoid))); traps = (XTrapezoid *)::realloc(traps, allocated * sizeof(XTrapezoid));
Q_CHECK_PTR(traps);
} }
traps[size].top = Q27Dot5ToXFixed(trap.top); traps[size].top = Q27Dot5ToXFixed(trap.top);
traps[size].bottom = Q27Dot5ToXFixed(trap.bottom); traps[size].bottom = Q27Dot5ToXFixed(trap.bottom);

View file

@ -184,13 +184,14 @@ bool QPainterPrivate::attachPainterPrivate(QPainter *q, QPaintDevice *pdev)
// redirections within the same paintEvent(), which should be enough // redirections within the same paintEvent(), which should be enough
// in 99% of all cases). E.g: A renders B which renders C which renders D. // in 99% of all cases). E.g: A renders B which renders C which renders D.
sp->d_ptr->d_ptrs_size = 4; sp->d_ptr->d_ptrs_size = 4;
sp->d_ptr->d_ptrs = (QPainterPrivate **)malloc(4 * sizeof(QPainterPrivate *)); sp->d_ptr->d_ptrs = (QPainterPrivate **)::malloc(4 * sizeof(QPainterPrivate *));
Q_CHECK_PTR(sp->d_ptr->d_ptrs); Q_CHECK_PTR(sp->d_ptr->d_ptrs);
} else if (sp->d_ptr->refcount - 1 == sp->d_ptr->d_ptrs_size) { } else if (sp->d_ptr->refcount - 1 == sp->d_ptr->d_ptrs_size) {
// However, to support corner cases we grow the array dynamically if needed. // However, to support corner cases we grow the array dynamically if needed.
sp->d_ptr->d_ptrs_size <<= 1; sp->d_ptr->d_ptrs_size <<= 1;
const int newSize = sp->d_ptr->d_ptrs_size * sizeof(QPainterPrivate *); const int newSize = sp->d_ptr->d_ptrs_size * sizeof(QPainterPrivate *);
sp->d_ptr->d_ptrs = q_check_ptr((QPainterPrivate **)realloc(sp->d_ptr->d_ptrs, newSize)); sp->d_ptr->d_ptrs = (QPainterPrivate **)::realloc(sp->d_ptr->d_ptrs, newSize);
Q_CHECK_PTR(sp->d_ptr->d_ptrs);
} }
sp->d_ptr->d_ptrs[++sp->d_ptr->refcount - 2] = q->d_ptr.data(); sp->d_ptr->d_ptrs[++sp->d_ptr->refcount - 2] = q->d_ptr.data();
q->d_ptr.take(); q->d_ptr.take();

View file

@ -426,7 +426,8 @@ inline void QScanConverter::allocate(int size)
{ {
if (m_alloc < size) { if (m_alloc < size) {
int newAlloc = qMax(size, 2 * m_alloc); int newAlloc = qMax(size, 2 * m_alloc);
m_intersections = q_check_ptr((Intersection *)realloc(m_intersections, newAlloc * sizeof(Intersection))); m_intersections = (Intersection *)::realloc(m_intersections, newAlloc * sizeof(Intersection));
Q_CHECK_PTR(m_intersections);
m_alloc = newAlloc; m_alloc = newAlloc;
} }
} }

View file

@ -394,9 +394,12 @@ void QTessellatorPrivate::Scanline::init(int maxActiveEdges)
if (!edges || maxActiveEdges > default_alloc) { if (!edges || maxActiveEdges > default_alloc) {
max_edges = maxActiveEdges; max_edges = maxActiveEdges;
int s = qMax(maxActiveEdges + 1, default_alloc + 1); int s = qMax(maxActiveEdges + 1, default_alloc + 1);
edges = q_check_ptr((Edge **)realloc(edges, s*sizeof(Edge *))); edges = (Edge **)::realloc(edges, s*sizeof(Edge *));
edge_table = q_check_ptr((Edge *)realloc(edge_table, s*sizeof(Edge))); Q_CHECK_PTR(edges);
old = q_check_ptr((Edge **)realloc(old, s*sizeof(Edge *))); edge_table = (Edge *)::realloc(edge_table, s*sizeof(Edge));
Q_CHECK_PTR(edge_table);
old = (Edge **)::realloc(old, s*sizeof(Edge *));
Q_CHECK_PTR(old);
} }
size = 0; size = 0;
old_size = 0; old_size = 0;
@ -554,8 +557,10 @@ void QTessellatorPrivate::Vertices::init(int maxVertices)
{ {
if (!storage || maxVertices > allocated) { if (!storage || maxVertices > allocated) {
int size = qMax((int)default_alloc, maxVertices); int size = qMax((int)default_alloc, maxVertices);
storage = q_check_ptr((Vertex *)realloc(storage, size*sizeof(Vertex))); storage = (Vertex *)::realloc(storage, size*sizeof(Vertex));
sorted = q_check_ptr((Vertex **)realloc(sorted, size*sizeof(Vertex *))); Q_CHECK_PTR(storage);
sorted = (Vertex **)::realloc(sorted, size*sizeof(Vertex *));
Q_CHECK_PTR(sorted);
allocated = maxVertices; allocated = maxVertices;
} }
} }
@ -727,7 +732,8 @@ void QTessellatorPrivate::cancelCoincidingEdges()
if (testListSize > tlSize - 2) { if (testListSize > tlSize - 2) {
tlSize = qMax(tlSize*2, 16); tlSize = qMax(tlSize*2, 16);
tl = q_check_ptr((QCoincidingEdge *)realloc(tl, tlSize*sizeof(QCoincidingEdge))); tl = (QCoincidingEdge *)::realloc(tl, tlSize*sizeof(QCoincidingEdge));
Q_CHECK_PTR(tl);
} }
if (n->flags & (LineBeforeStarts|LineBeforeHorizontal)) { if (n->flags & (LineBeforeStarts|LineBeforeHorizontal)) {
tl[testListSize].start = n; tl[testListSize].start = n;

View file

@ -437,7 +437,8 @@ void QTextTablePrivate::update() const
nRows = (cells.size() + nCols-1)/nCols; nRows = (cells.size() + nCols-1)/nCols;
// qDebug(">>>> QTextTablePrivate::update, nRows=%d, nCols=%d", nRows, nCols); // qDebug(">>>> QTextTablePrivate::update, nRows=%d, nCols=%d", nRows, nCols);
grid = q_check_ptr((int *)realloc(grid, nRows*nCols*sizeof(int))); grid = (int *)::realloc(grid, nRows*nCols*sizeof(int));
Q_CHECK_PTR(grid);
memset(grid, 0, nRows*nCols*sizeof(int)); memset(grid, 0, nRows*nCols*sizeof(int));
QTextDocumentPrivate *p = pieceTable; QTextDocumentPrivate *p = pieceTable;
@ -461,7 +462,8 @@ void QTextTablePrivate::update() const
cellIndices[i] = cell; cellIndices[i] = cell;
if (r + rowspan > nRows) { if (r + rowspan > nRows) {
grid = q_check_ptr((int *)realloc(grid, sizeof(int)*(r + rowspan)*nCols)); grid = (int *)::realloc(grid, sizeof(int)*(r + rowspan)*nCols);
Q_CHECK_PTR(grid);
memset(grid + (nRows*nCols), 0, sizeof(int)*(r+rowspan-nRows)*nCols); memset(grid + (nRows*nCols), 0, sizeof(int)*(r+rowspan-nRows)*nCols);
nRows = r + rowspan; nRows = r + rowspan;
} }