summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qmalloc.cpp
diff options
context:
space:
mode:
authorMartin Smith <martin.smith@nokia.com>2010-11-11 08:51:57 (GMT)
committerMartin Smith <martin.smith@nokia.com>2010-11-11 08:51:57 (GMT)
commit6315183497eee1867c7ed899c6ea22fb66a4cfed (patch)
tree3d57e0e79c8c0a0932ec18c97fa5851a00eecd98 /src/corelib/global/qmalloc.cpp
parent749632c12feb8a43594d52309ea630c2bc8c5161 (diff)
parentfce752ba402535a62e420a83483d0f92623d684a (diff)
downloadQt-6315183497eee1867c7ed899c6ea22fb66a4cfed.zip
Qt-6315183497eee1867c7ed899c6ea22fb66a4cfed.tar.gz
Qt-6315183497eee1867c7ed899c6ea22fb66a4cfed.tar.bz2
Merge branch '4.7' of git@scm.dev.nokia.troll.no:qt/qt-doc-team into 4.7
Diffstat (limited to 'src/corelib/global/qmalloc.cpp')
-rw-r--r--src/corelib/global/qmalloc.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/corelib/global/qmalloc.cpp b/src/corelib/global/qmalloc.cpp
index 090998c..028a0a5 100644
--- a/src/corelib/global/qmalloc.cpp
+++ b/src/corelib/global/qmalloc.cpp
@@ -90,8 +90,6 @@ void *qReallocAligned(void *oldptr, size_t newsize, size_t oldsize, size_t align
return newptr + 1;
}
- union { void *ptr; void **pptr; quintptr n; } real, faked;
-
// qMalloc returns pointers aligned at least at sizeof(size_t) boundaries
// but usually more (8- or 16-byte boundaries).
// So we overallocate by alignment-sizeof(size_t) bytes, so we're guaranteed to find a
@@ -100,19 +98,21 @@ void *qReallocAligned(void *oldptr, size_t newsize, size_t oldsize, size_t align
// However, we need to store the actual pointer, so we need to allocate actually size +
// alignment anyway.
- real.ptr = qRealloc(actualptr, newsize + alignment);
- if (!real.ptr)
+ void *real = qRealloc(actualptr, newsize + alignment);
+ if (!real)
return 0;
- faked.n = real.n + alignment;
- faked.n &= ~(alignment - 1);
+ quintptr faked = reinterpret_cast<quintptr>(real) + alignment;
+ faked &= ~(alignment - 1);
+
+ void **faked_ptr = reinterpret_cast<void **>(faked);
// now save the value of the real pointer at faked-sizeof(void*)
// by construction, alignment > sizeof(void*) and is a power of 2, so
// faked-sizeof(void*) is properly aligned for a pointer
- faked.pptr[-1] = real.ptr;
+ faked_ptr[-1] = real;
- return faked.ptr;
+ return faked_ptr;
}
void qFreeAligned(void *ptr)