From d58e2ae672012723117954b9382e6364b8ed3c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 19 Jun 2024 13:38:31 +0200 Subject: [PATCH] Text: tighten up align*() internals with unreachable assertions. There shouldn't be any other values passed to these. Compilers, don't even attempt to say that the alignment value is now maybe uninitialized, I'm watching you! --- src/Magnum/Text/Renderer.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Magnum/Text/Renderer.cpp b/src/Magnum/Text/Renderer.cpp index ab995c413..fd76df20c 100644 --- a/src/Magnum/Text/Renderer.cpp +++ b/src/Magnum/Text/Renderer.cpp @@ -195,7 +195,7 @@ Range2D alignRenderedLine(const Range2D& lineRectangle, const LayoutDirection di /** @todo this again assumes horizontal direction, needs to be updated once vertical (and possibly mixed horizontal/vertical) text is possible */ - Float alignmentOffsetX = 0.0f; + Float alignmentOffsetX; if((UnsignedByte(alignment) & Implementation::AlignmentHorizontal) == Implementation::AlignmentLeft) alignmentOffsetX = -lineRectangle.left(); else if((UnsignedByte(alignment) & Implementation::AlignmentHorizontal) == Implementation::AlignmentCenter) { @@ -206,6 +206,7 @@ Range2D alignRenderedLine(const Range2D& lineRectangle, const LayoutDirection di } else if((UnsignedByte(alignment) & Implementation::AlignmentHorizontal) == Implementation::AlignmentRight) alignmentOffsetX = -lineRectangle.right(); + else CORRADE_INTERNAL_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ /* Shift all positions */ for(Vector2& i: positions) @@ -224,8 +225,10 @@ Range2D alignRenderedBlock(const Range2D& blockRectangle, const LayoutDirection /** @todo this assumes vertical layout advance, needs to be updated once other directions are possible */ - Float alignmentOffsetY = 0.0f; - if((UnsignedByte(alignment) & Implementation::AlignmentVertical) == Implementation::AlignmentBottom) + Float alignmentOffsetY; + if((UnsignedByte(alignment) & Implementation::AlignmentVertical) == Implementation::AlignmentLine) + alignmentOffsetY = 0.0f; + else if((UnsignedByte(alignment) & Implementation::AlignmentVertical) == Implementation::AlignmentBottom) alignmentOffsetY = -blockRectangle.bottom(); else if((UnsignedByte(alignment) & Implementation::AlignmentVertical) == Implementation::AlignmentMiddle) { alignmentOffsetY = -blockRectangle.centerY(); @@ -235,6 +238,7 @@ Range2D alignRenderedBlock(const Range2D& blockRectangle, const LayoutDirection } else if((UnsignedByte(alignment) & Implementation::AlignmentVertical) == Implementation::AlignmentTop) alignmentOffsetY = -blockRectangle.top(); + else CORRADE_INTERNAL_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ /* Shift all positions */ for(Vector2& i: positions)