diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2022-02-09 10:01:26 -0800 |
|---|---|---|
| committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-02-09 20:13:34 -0800 |
| commit | 6586b030d163a4a63328cb83a25dd21411dcbb9e (patch) | |
| tree | 0c5856d790aeb819524e78d29eb2680d9efc26d4 /src/corelib/global/qmalloc.cpp | |
| parent | 52a83658c3e930e4b751ea2546baf9b13b1fce5b (diff) | |
Fix GCC12 warning about using a pointer after realloc()
qmalloc.cpp:92:18: warning: pointer may be used after ?void* realloc(void*, size_t)? [-Wuse-after-free]
92 | qptrdiff oldoffset = static_cast<char *>(oldptr) - static_cast<char *>(actualptr);
| ^~~~~~~~~
Pick-to: 6.2 6.3
Change-Id: I74249c52dc02478ba93cfffd16d230165b6f030f
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/global/qmalloc.cpp')
| -rw-r--r-- | src/corelib/global/qmalloc.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/global/qmalloc.cpp b/src/corelib/global/qmalloc.cpp index aeba9ed19b3..3be1bf53d48 100644 --- a/src/corelib/global/qmalloc.cpp +++ b/src/corelib/global/qmalloc.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -80,6 +80,7 @@ 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. + qptrdiff oldoffset = oldptr ? static_cast<char *>(oldptr) - static_cast<char *>(actualptr) : 0; void *real = realloc(actualptr, newsize + alignment); if (!real) return nullptr; @@ -89,7 +90,6 @@ void *qReallocAligned(void *oldptr, size_t newsize, size_t oldsize, size_t align void **faked_ptr = reinterpret_cast<void **>(faked); if (oldptr) { - qptrdiff oldoffset = static_cast<char *>(oldptr) - static_cast<char *>(actualptr); qptrdiff newoffset = reinterpret_cast<char *>(faked_ptr) - static_cast<char *>(real); if (oldoffset != newoffset) memmove(faked_ptr, static_cast<char *>(real) + oldoffset, qMin(oldsize, newsize)); |
