diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2024-07-02 11:23:09 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2024-07-05 20:21:51 +0000 |
| commit | f699248c0f3ad44f09a422304870f40c1998a1a5 (patch) | |
| tree | 38b3016f68f400109dad58f6a23e70667854349b /src/tools/uic/cpp/cppwriteincludes.cpp | |
| parent | 9a8768c7159869aa216b7328c69f4b80f26f467e (diff) | |
QArrayDataOps: fix appendUninitialized()
... to be strongly exception-safe and call placement new correctly.
The old code could call user-provided overloads of new, because it
didn't cast the pointer to void* before calling placement-new. It
would also "randomly" stop when an exception was thrown. It correctly
updated the size of the container only after successful construction
of the element, but that's just weak exception-safety. There's no
reason this operation shouldn't be strongly exception-safe.
So instead of a raw loop around raw placement-new, use the
corresponding raw memory STL algorithms. They handle exceptions and
call placement-new correctly, and the code is both simpler as a
consequence, and more efficient, as it updates this->size only once.
Found in API-review.
Amends 73bf1c1a9bcc2615370d6a199420da0c6f380a44.
Pick-to: 6.8
Change-Id: I535f393a3c378e1eea104bd3a05a274b9ec17964
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/tools/uic/cpp/cppwriteincludes.cpp')
0 files changed, 0 insertions, 0 deletions
