From 31ea93dd0df820c1491c627644f44f380102689f Mon Sep 17 00:00:00 2001 From: Xiretza Date: Tue, 19 Jan 2021 16:06:49 +0100 Subject: [PATCH] [client] Fix compiler warnings about potentially uninitialized variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Build failed with _FORTIFY_SOURCE enabled because the compiler couldn't ensure the switch statements didn't hit the default arm and thus wouldn't define the variables. Adding a statically failing assert makes sure that all code paths either define the variables or fail early. $ cd client $ env CFLAGS='-O1 -D_FORTIFY_SOURCE=1' cmake -B build/ $ make -C build [...] client/renderers/EGL/egl.c: In function ‘egl_calc_mouse_size’: client/renderers/EGL/egl.c:299:36: error: ‘h’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 299 | (this->mouseHeight * (1.0f / h)) * this->scaleY | ~~~~~~^~~~ --- client/renderers/EGL/egl.c | 5 +++++ client/src/main.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/client/renderers/EGL/egl.c b/client/renderers/EGL/egl.c index 5a9858a0..543acfc3 100644 --- a/client/renderers/EGL/egl.c +++ b/client/renderers/EGL/egl.c @@ -34,6 +34,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #endif +#include + #include "app.h" #include "model.h" #include "shader.h" @@ -288,6 +290,9 @@ static void egl_calc_mouse_size(struct Inst * this) w = this->format.height; h = this->format.width; break; + + default: + assert(!"unreachable"); } switch((this->format.rotate + this->rotate) % LG_ROTATE_MAX) diff --git a/client/src/main.c b/client/src/main.c index 14f783de..73e177df 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -192,6 +192,9 @@ static void updatePositionInfo(void) srcW = g_state.srcSize.y; srcH = g_state.srcSize.x; break; + + default: + assert(!"unreachable"); } if (params.keepAspect) @@ -1242,6 +1245,9 @@ inline static void localCurToGuest(struct DoublePoint *guest) * g_cursor.scale.y; guest->y = (point.x - g_state.dstRect.x) * g_cursor.scale.x; break; + + default: + assert(!"unreachable"); } }