diff options
author | Marc Mutz <[email protected]> | 2025-03-03 11:52:54 +0100 |
---|---|---|
committer | Marc Mutz <[email protected]> | 2025-03-04 17:19:46 +0100 |
commit | 43874ec9f8e05798212d4f72f9bcbe23b8f30cac (patch) | |
tree | a5e0508e0cf0d11883bb880cfca0f779c530cee0 | |
parent | bcd29a9eab00c77bc402b9d4242f097d19c92044 (diff) |
QGridLayout: make QHVContainer's preconditions machine-readable
Coverity complains that other() computes an address that's out of
m_data's bounds, and that's correct, if the argument isn't either
Qt::Horizontal or Qt::Vertical (they're flags, so Coverity assumes
that 0 and Vertical|Horizonal are valid arguments, too), but as the
doc block above the class suggests, this is not supported. So add
Q_ASSERTs to map() and mapOther(), and drop the noexcept of functions
that call these now.
Not picking to older branches in case Coverity is right and I am
wrong.
Amends 46a1cf915096ab056ad3bfd1d42fd504c04763cd.
Coverity-Id: 427374
Change-Id: I47a2821e99dd99666a170f2bb2859c1d6351b50e
Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r-- | src/gui/util/qgridlayoutengine_p.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/gui/util/qgridlayoutengine_p.h b/src/gui/util/qgridlayoutengine_p.h index e00c2c5e483..159e4a5a25a 100644 --- a/src/gui/util/qgridlayoutengine_p.h +++ b/src/gui/util/qgridlayoutengine_p.h @@ -72,12 +72,14 @@ class QHVContainer { static_assert(Qt::Horizontal == 0x1); static_assert(Qt::Vertical == 0x2); - static constexpr int map(Qt::Orientation o) noexcept + static constexpr int map(Qt::Orientation o) { + Q_ASSERT(o == Qt::Horizontal || o == Qt::Vertical); // Q_PRE return int(o) - 1; } - static constexpr int mapOther(Qt::Orientation o) noexcept + static constexpr int mapOther(Qt::Orientation o) { + Q_ASSERT(o == Qt::Horizontal || o == Qt::Vertical); // Q_PRE return 2 - int(o); } public: @@ -86,11 +88,11 @@ public: : m_data{h, v} {} QHVContainer() = default; - constexpr T &operator[](Qt::Orientation o) noexcept { return m_data[map(o)]; } - constexpr const T &operator[](Qt::Orientation o) const noexcept { return m_data[map(o)]; } + constexpr T &operator[](Qt::Orientation o) { return m_data[map(o)]; } + constexpr const T &operator[](Qt::Orientation o) const { return m_data[map(o)]; } - constexpr T &other(Qt::Orientation o) noexcept { return m_data[mapOther(o)]; } - constexpr const T &other(Qt::Orientation o) const noexcept { return m_data[mapOther(o)]; } + constexpr T &other(Qt::Orientation o) { return m_data[mapOther(o)]; } + constexpr const T &other(Qt::Orientation o) const { return m_data[mapOther(o)]; } constexpr void transpose() noexcept { qSwap(m_data[0], m_data[1]); } constexpr QHVContainer transposed() const |