summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qnativesocketengine_winrt_p.h
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2018-03-30 18:14:54 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2018-04-06 10:15:40 +0000
commit093cf19f1efdfbba3edb76547917a51e5b8cdba5 (patch)
tree5f015034b6abe90761d0e83e6b83b91f188434da /src/network/socket/qnativesocketengine_winrt_p.h
parent54dcbf49927954e913c1f65d2c67396f0bec14f9 (diff)
QVector2D/QVector3D/QVector4D: ensure well-defined behavior
The purpose of QVectorND classes is to store N floats packed together. One of their usecases is to build arrays of them, then using them as an array of floats (e.g. when uploading data to OpenGL). The design of the class however has a major problem: using separate members does not guarantee that the compiler does not insert padding between them (although that could be static-asserted). What's worse, the implementation of operator[] just does pointer arithmetic on the first member of the class; that's undefined behavior, and will trigger ASAN warnings in the future [1]. Solve both problems by using an array of floats instead of individual x/y/z/w members. Now the compiler is not allowed to insert hidden padding any more, and makes operator[] well-defined. However this might be a BIC (IF the compiler added paddings in the past): hence, add static_asserts checking that the memory layout of the classes hasn't changed. For good measure, also add static_asserts checking 1) that the class is standard_layout, so it's safe to reinterpret_cast it to its first (and only) member; 2) that there's no padding at the _end_ of the class. Note: an alternative solution to the operator[] problem could've been leaving the class untouched, and reimplementing the operator via a switch. Unfortunately none between GCC, clang and MSVC compile away the switch, dramatically pessimizing the code. [1] https://github.com/google/sanitizers/wiki/AddressSanitizerIntraObjectOverflow Change-Id: Iec00ffb6044c58cf728de1754a780068f88152cb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/network/socket/qnativesocketengine_winrt_p.h')
0 files changed, 0 insertions, 0 deletions